Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging Clientside JavaScript Errors on Server [closed]

Im running a ASP.NET Site where I have problems to find some JavaScript Errors just with manual testing.

Is there a possibility to catch all JavaScript Errors on the Clientside and log them on the Server i.e. in the EventLog (via Webservice or something like that)?

like image 609
MADMap Avatar asked Sep 23 '08 06:09

MADMap


People also ask

How do I log JavaScript errors on my server?

If you're wanting to log the client-side errors back to the server you're going to have to do some kind of server processing. Best bet would be to have a web service which you can access via JavaScript (AJAX) and you pass your error log info to it.

Why am I getting a JavaScript error?

Grammatical mistakes, such as missing parentheses or unmatched brackets, are the major causes of syntax errors in JavaScript. For example, when you must use conditional statements to address multiple conditions, you may miss providing the parentheses as required, leading to syntax flaws.


2 Answers

You could try setting up your own handler for the onerror event and use XMLHttpRequest to tell the server what went wrong, however since it's not part of any specification, support is somewhat flaky.

Here's an example from Using XMLHttpRequest to log JavaScript errors:

window.onerror = function(msg, url, line) {   var req = new XMLHttpRequest();   var params = "msg=" + encodeURIComponent(msg) + '&url=' + encodeURIComponent(url) + "&line=" + line;   req.open("POST", "/scripts/logerror.php");   req.send(params); }; 
like image 56
Jonny Buchanan Avatar answered Sep 18 '22 03:09

Jonny Buchanan


Short answer: Yes, it is possible.

Longer answer: People have already written about how you can (at least partially) solve this issue by writing your own code. However, do note that there are services out there that seems to have made sure the JS code needed works in many browsers. I've found the following:

  • http://trackjs.com
  • https://www.atatus.com
  • http://jserrlog.appspot.com
  • http://muscula.com
  • https://sentry.io
  • https://rollbar.com
  • https://catchjs.com

I can't speak for any of these services as I haven't tried them yet.

like image 24
Ztyx Avatar answered Sep 19 '22 03:09

Ztyx