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 m开发者_如何学编程achine?
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
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.
精彩评论