Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracking visitor JS errors? [closed]

Is it possible to track JS errors that a visitor encounters? Obviously we do our own testing, but from time to time a visitor will be running a certain browser version, or have a particular plugin, at it'll cause a JS error. Likewise sometimes an error in the JS gets to production unnoticed.

It would be extremely useful if we could somehow capture these events, and ajax a script on our server with details of the error so that we could attempt to fix the issue.

UPDATE: Thanks for the feedback. Typically after posting I managed to find:
Logging Clientside JavaScript Errors on Server
Which had the stuff on window.onerror and also some interesting things about JQuery and a FireFox onerror bug that still hasn't been fixed for years...

like image 290
Cosmicnet Avatar asked Feb 27 '11 21:02

Cosmicnet


2 Answers

Yes, use window.onerror.

For the AJAX logging part, don't rely on any code that might run after the error has occurred. You might want to keep it as simple as possible by making the request with a dynamically-inserted script tag with the source set to be your server script with the data as GET parameters. However, be aware that using GETs will limit you in terms of numbers of characters in the src path (~2000 in IE).

However you do it, it is important to keep it simple as you don't want your error-logging code to be prone to errors in exactly the situations where its most likely to run (the edge cases).

You'll want to disable this in your non-production environments or it could mask problems.

like image 189
Dan S Avatar answered Oct 26 '22 23:10

Dan S


Yes, you can use the window.onerror handler.

like image 43
Matthew Flaschen Avatar answered Oct 27 '22 00:10

Matthew Flaschen