I’m trying to understand why Firefox (I’m using 15 but it’s the same even in nightly) is not behaving like WebKit when trying to access error event information.
This one works everywhere:
window.onerror = function(message, lineno, filename) { }
But of course I don’t want to use this.
The right thing to do is:
window.addEventListener('error', function(e) {
console.log(e.message);
}, false);
Unfortunately this one only works in WebKit. In Firefox the handler is called, but the e event is almost empty: no message, no line number, no filename properties.
The very minimal test is here: http://jsbin.com/efexiw/1/edit
I don’t think this is a bug, though… so the question is: how do I get the error details in recent Firefox?
The HTML5 specification requires that a parse failure causes the browser to:
Where "report the error" includes the steps
Thus, any HTML5-compliant browser will report parse-time error events on
window, which include amessageattribute set to a "user-agent-defined string describing the error in a helpful manner." Any browser version that fails to do this is not yet HTML5 compliant in this regard.Previously (at the time this question was written),
window.onerrorgave information that was not provided bywindow.addEventListener("error"). If you must use an old version of Firefox, you can safely usewindow.onerror: