I want to log JavaScript errors so I'm overriding window.onerror
like this:
window.onerror = function(message, file, lineNumber) {
var browser_ = encodeURI(navigator.appVersion);
var error_ = encodeURI("msg:"+ message + "\n\tfile:"+file+"\n\tln:"+lineNumber);
var user_ = encodeURI("");
...
return false;
}
I've seen some people return true
and some return false
. Which is right and why? One post mentioned something about have you have to return true or Firefox will handle the error it's own way. What??
I want to log JavaScript errors so I'm overriding window.onerror
like this:
window.onerror = function(message, file, lineNumber) {
var browser_ = encodeURI(navigator.appVersion);
var error_ = encodeURI("msg:"+ message + "\n\tfile:"+file+"\n\tln:"+lineNumber);
var user_ = encodeURI("");
...
return false;
}
I've seen some people return true
and some return false
. Which is right and why? One post mentioned something about have you have to return true or Firefox will handle the error it's own way. What??
1 Answer
Reset to default 32From MDN on window.onerror
:
When the function returns
true
, this prevents the firing of the default event handler.
See also chromium Issue 92062:
In Chrome, returning
true
from window.onerror allows the error to propagate, and returningfalse
suppresses it.This is the inverse of the behavior in Firefox and IE, where returning 'true' suppresses the error, but returning
false
propagates it.
Note: the issue mentioned above was fixed, behavior is now as mentioned on MDN for all browsers.