Javascript Error

Seven months ago tempus fugit a client asked if I could create a smoke test that would visit all pages of the application and report if there were any JavaScript errors. Since we already had a smoke test that visited all pages and took screenshots, I thought it would be easy to do. All I had to do was to figure out how to catch JavaScript errors with Watir. Turns out Selenium does not have API for checking for JavaScript errors on the page yet. How are Selenium and Watir connected? Watir WebDriver (part of Watir project) uses WebDriver (part of Selenium project) to drive browsers.

I have found a solution (with some help at Google Groups and Stack Overflow), but it was neither simple nor elegant. Then Jari Bakken pointed me to his Gist.