If I override window.onerror in javascript should I return true or false?

12,715

From 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 returning false 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.

Share:
12,715
tooshel
Author by

tooshel

Dad, Husband, Developer, Woodworker, AFOL. And of course #SOreadytohelp

Updated on June 24, 2022

Comments

  • tooshel
    tooshel almost 2 years

    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??