I have just implemented server side error logging on javascript errors on a project at work. There is a mixture of legacy code and new code using jQuery.
I use a combination of window.onerror
and wrapping the jQuery event handlers and onready function with an error handling function (see: JavaScript Error Tracking: Why window.onerror Is Not Enough).
window.onerror
: catches all errrors in IE (and most errors in Firefox), but does nothing in Safari and Opera.
- jQuery event handlers: catches jQuery event errors in all browsers.
- jQuery ready function: catches initialisation errors in all browsers.
Once I have caught the error, I add some extra properties to it (url, browser, etc) and then post it back to the server using an ajax call.
On the server I have a small page which just takes the posted arguments and outputs them to our normal server logging framework.
I would like to open source the code for this (as a jQuery plugin). If anyone is interested let me know, it would help to convince the bosses!