Can you globally monitor javascript errors in all browsers? yes!

Fri, Nov 29, 2013 at 10:35PM

I just found out you can monitor javascript errors globally with this Javascript code:

window.onerror=function(message, url, linenumber){}

Surprisingly, that works on all the modern browsers we need to support already include IE 5.5+, Chrome, Firefox, Opera, Safari.  Chrome also gives you a reference to a stacktrace as an extra argument.  IE10, also has 4 arguments.  So there is a little bit of browser checking involved to build a feature-rich correct solution for this.

I'm going to setup a log / email alert system for this right away, and start fixing all of these as they come in on all my existing sites.

Imagine all the errors you don't know about that could be costing people money.  Forms that can't be submitted,  layouts that are broken, browsers not properly supported, etc.   It's a shame I didn't know about this sooner, but the good news it will be easy to add this error capturing & logging feature on all sites.

Why is it easy for me?  Well all the work I've done in the last 10 years is running on the same code pretty much.  So I just have to drop this in to the framework, and it will start notifying me of the problems.

11/30/2013 Update: I just finished an initial version of my global javascript error logging system for Jetendo CMS.

The system is sending me so many errors alert emails, that I had to throttle the number of emails sent to me to just a few per minute.  However, I'm logging everything.  Now I can fix hundreds of previously undiscovered bugs.  I wanted to do this immediately after discovering that window.onerror is able to trap these errors in all browsers even old ones like IE 5.5+.  I handled a lot of details with various browsers and made it very nice and integrated with Jetendo's logging systems & visual interface.   I also integrated an open source third party javascript stack trace project which makes it provide more information to save developer's time.

Bookmark & Share