How do I read console window errors from Chrome using JavaScript?
This lib seems to catch console messages : ianpgall/js-console-listener (I never tested it)
A library that allows you to listen for console events.
Basically, it overrides the existing console methods and replace it with its own methods.
If you want to catch windows error, you just need to use the
window.onerror
listener. If you return true
in your callback, then
the propagation of the error will stop and won ‘t be log in the console
(see the docs :
GlobalEventHandlers.onerror
)
window.onerror = function myErrorHandler(err, url, line) {
//Do some stuff
return false; // so you still log errors into console
}
This text was originally published in quora.