Monday, December 23

Tag: window.onerror

Web Tricks

Capture and Report JavaScript Errors with window.onerror

  onerror is a special browser event that fires whenever an uncaught JavaScript error has been thrown. It's one of the easiest ways to log client-side errors and report them to your servers. It's also one of the major mechanisms by which Sentry's client JavaScript integration (raven-js) works. You listen to the onerror event by assigning a function to window.onerror: window.onerror = function(msg, url, lineNo, columnNo, error) { // ... handle error ... return false; } When an error is thrown, the following arguments are passed to the function: msg – The message associated with the error, e.g. "Uncaught ReferenceError: foo is not defined" url – The URL of the script or document associated with the error, e.g. "/dist/app.js" lineNo – The line number (if available...