window.onerror not working in chrome window.onerror not working in chrome google-chrome google-chrome

window.onerror not working in chrome


window.onerror is not triggered when the console directly generates an error. It can be triggered via setTimeout though, e.g., setTimeout(function() { notThere(); }, 0);

Possible duplicate: Chrome: Will an error in code invoked from the dev console trigger window.onerror?


The window.onerror works in Chrome (see jsfiddle - http://jsfiddle.net/PWSDF/), but apparently not in the console - which makes some sense.


Some other reasons that you may not be able to handle errors in window.onerror (apart from the mentioned ones):

  • Another library sets window.onerror after you.
  • If you are using Angular, errors wont pass through window.onerror. You have to handle them using this factory:

        .factory('$exceptionHandler', function() {        return function errorCatcherHandler(exception, cause) {            console.error(exception);            if (window.OnClientError) window.OnClientError(exception);        };    })

See:

https://docs.angularjs.org/api/ng/service/$exceptionHandler

http://bahmutov.calepin.co/catch-all-errors-in-angular-app.html