Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically reporting javascript errors to the developer

As most production environments we have setup something to send us a notification if there is an error in our web application. The problem is ofcourse that this only covers errors on the server side.

My question to the community is: What are you doing about client side errors, especially in javascript?

And what about other quality of service issues, such as slow processing and other things that might be due to the client machine?

like image 594
Cine Avatar asked Apr 12 '10 10:04

Cine


People also ask

Which area of the developer tools in a browser shows JavaScript errors?

From the menu, select Developer > Developer tools and select Console. The error console will open. Select JavaScript and Errors from the two dropdowns.

Do browsers display JavaScript errors?

In Chrome, navigate to Tools > Advanced > Error Console. The error console will open. Select JavaScript and Errors from the two drop downs. To find the error location, expand one of the errors.


2 Answers

You can handle client side JavaScript errors with window.onerror event

Inside the handler make an Ajax request to your server side error miner and log the error.

http://www.javascriptkit.com/javatutors/error.shtml

Hovewer window.onerror is not supported in all browsers, jQuery can fill up the gap with its own event handler: a combination of window.onerror and jQuery(window).error should suffice

like image 193
Juraj Blahunka Avatar answered Oct 29 '22 18:10

Juraj Blahunka


There's not a great deal you can do about JavaScript errors at the client end. You can trap window.onerror and use it to AJAX a report back, but:

(a) it's not supported in WebKit or Opera. To catch all errors you would have to wrap every direct-execution, event and timeout entry point in a try { ... }, which is very messy and gives you even less information than the onerror handler.

(b) you will likely be swamped with error reports you can't do anything about, with little debugging possible due to lack of information. You might be able to get away with it on an application that is only accessed by customers you know, but on a public-access site, a lot of errors will be spurious. Stuff caused by factors like:

  • connections to sites hosting scripts or AJAX failing or being blocked by firewalls;

  • unexpected security settings (browsers have options to block many interfaces arbitrarily);

  • broken browser add-ons, GreaseMonkey-like scripts, filtering proxies and bogus “Internet Security” tools messing with your code;

  • unsupported agents that behave oddly, like mobile browsers (especially the appalling IEMobile) and, if they have access, automated-browser bots;

  • many errors caused by third-party content like adverts, if you have any.

Again, for a limited-use application where you can directly contact any user who is experiencing problems, it might be of use, but for a site used by the general public it's a non-starter.

It's best to use ‘progressive enhancement’ to ensure that your application still works when JavaScript fails.

like image 30
bobince Avatar answered Oct 29 '22 17:10

bobince