Handling javascript errors as always been sort of a problem for me. Testing every combination possible in a big application is hard, and there is always a chance you will miss something.

Of course, we should always strive to make an application as bug free as possible, but users seems to always find a way to break it. You can always expect them to do something you never have think of, and this is one of the reason I created this plugin.

When a javascript error is detected, this plugin will do an ajax request to your server and then sends an email, of course you could also log it in a database. It’s certainly not a revolutionary idea, but still, I was finding the idea cool enough to add it to my list of online plugin.

It’s also very useful for debugging big live applications that you have not written. In which case you want to know if some users hit javascript errors already.

Download the source code

Integration

Load the plugin just after the jQuery library

$(document).jsErrorHandler();

Your done.

Options

By default the plugin automatically fetch the domain and add it to the email subject, but you can overwrite it.

You can also define a from attribute, I would highly recommend that you change the from setting in the plugin file (jquery.onerror.js) if your going to use this plugin on multiple websites.

$(document).jsErrorHandler({ from: "support@youremail.com", website: document.domain });

The Email

The email received will look like this:

A javascript error has been detected on www.position-absolute.com

Error: variable is not defined

Url: http://www.position-absolute.com/creation/onerror/

Line: 21

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0

Limitation

The plugin works on:

Firefox 3.6+

Chrome Latest

IE 7+

It does not work on Safari (but it will not break your application)