Logging Clientside JavaScript Errors on Server [closed]

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);
};

Leave a Comment