Right now we are working on a way to catch errors that occur in JavaScript. We have everything working in browsers including and after IE9.
In modern browsers we can wrap window.EventTarget.prototype.addEventListener
with a function that does a try/catch
in order to capture errors. For example we can do this:
var addEventListener = window.EventTarget.prototype.addEventListener;
window.EventTarget.prototype.addEventListener = function (event, callback, bubble) {
return addEventListener.call(this, event, WATCH_FUNCTION(callback), bubble)
};
The WATCH_FUNCTION
above has our try/catch
in it. Right now we cannot figure out a way to wrap the attachEvent
that exists on an element in IE8. For example:
var myObject = document.getElementById('my-id');
myObject.attachEvent('onclick', function () {reference-to-undefined-var});
Our hope is to wrap the error that is going to be raised by the attached event. Right now we cannot figure out how to always wrap attachEvent. We will be a third party library so we cannot force people to use a different form of attaching events.
As a note for anyone who looks at this question I have tried to override the following and none seem to work:
Object.prototype.attachEvent
Element.prototype.attachEvent
window.attachEvent