This is aimed primarily for mobile browser engines.
In lieu of this missing function, there's this library. It instruments a
those callbacks in a try/catch. It will then report the exception to you via
console.log(). In addition, it will display a little bit of context about
the function invocation that specified the callback, as this may help you
further narrow down the problem.
For instance, if you open the file
test/tests.html in a browser, and
click on the button
setTimeout, it will run a
setTimeout() function with a
callback that causes a runtime exception. You should then see the following
in the console:
exception executing callback: TypeError: Cannot set property 'x' of null callsite: setTimeout(callbackWithError, 500) stacktrace follows TypeError: Cannot set property 'x' of null at functionThatThrowsError (http://example.com/log-callback-error/test/tests.js:80:9) at callbackWithError (http://example.com/log-callback-error/test/tests.js:74:5) at http://example.com/log-callback-error/log-callback-error.js:65:21
Note that you'll only see the stacktrace if your browser supports the
property on exceptions (at least Opera and V8-enabled browsers; Safari flavors
do not yet support the
The stacktrace is the stack at the time the exception occurred.
The second line of the output, labelled with
is the context of the call. It provides
some information about how the callback was initially registered. In the case
above, it provides the name of the callback function registered, along with
the timeout millisecond value.
Add the line
The following functions are overridden to provide the exception callback handling:
window.setTimeout() window.setInterval() window.addEventListener() Node.prototype.addEventListener() XMLHttpRequest.prototype.addEventListener()
Node.prototype.addEventListener() override applies to all DOM nodes,
XMLHttpRequest flavor applies to all XHR
Specifically note, these are the only things overridden. Need more? Fork, add, push.
It seems likely that the
onblahblah flavored event properties will never
be supported, because the DOM host objects suck.