Reputation: 370
My web page is catching errors with window.onerror
and than sends the error to the server for logging. This is working well. However, I stopped seeing the errors on Chrome and Firefox console logs. This makes debugging the application more difficult. Is there any way I can keep using window.onerror
yet see the error logs on the console without writing it myself on the onerror
? When Chrome is writing the error to the console (if onerror
is not used) the stacktrace and navigation to the error source are really helpful.
Upvotes: 2
Views: 3838
Reputation: 14875
You have to return false
at the end of the error handler to let the default error handler (which logs to the console) run.
window.onerror = function myErrorHandler(errorMsg, url, lineNumber) {
//Do some of your ajax requests or whatever
return false;
}
Out of MDN:
When the function returns true, this prevents the firing of the default event handler.
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onerror
Upvotes: 9