Note that there are some explanatory texts on larger screens.

plurals
  1. POwindow.onerror not firing in Firefox
    text
    copied!<p>I'm trying to create a javascript error logging infrastructure.</p> <p>I'm trying to set <code>window.onerror</code> to be my error handler. It works in IE 6, but when I run it in Firefox, it runs into some conflicting <code>onerror</code> method. </p> <pre><code>var debug = true; MySite.Namespace.ErrorLogger.prototype = { //My error handling function. //If it's not in debug mode, I should get an alert telling me the error. //If it is, give a different alert, and let the browser handle the error. onError: function(msg, url, lineNo) { alert('onError: ' + msg); if (!debug) { alert('not debug mode'); return true; } else { alert(msg); return false; } } } //Document ready handler (jQuery shorthand) $(function() { log = $create(MySite.Namespace.ErrorLogger); window.onerror = log.onError; $(window).error(function(msg, url, line) { log.onError(msg, url, line); }); }); </code></pre> <p>If I use <code>setTimeout("eval('a')", 1);</code> where '<code>a</code>' is an undefined variable, my error handler is what's fired (it works). However, my error-logger needs to catch all errors thrown by clients accessing the website, not just incorrect code in one place.</p> <p>The code is on a .js page that is being called from the base page (C#) of a website. The site also uses jQuery, so I have a function that overrides the jQuery bind function, and that function works fine in both Firefox 3 and IE 6.</p> <p>I know that Firefox is seeing the error because it shows up in both the Error Console and Firebug, but <em>my</em> <code>window.onerror</code> function is still not being called.</p> <p>Any thoughts on how to override what Firefox is doing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload