I have a function attached to window.onerror
window.onerror = function(errorMsg, url, line) {
window.alert('asdf');
};";
This works fine in firefox, chrome and IE, but it doesn't work in safari. From some digging I read somewhere that safari does not support onerror. The post however was a few years old. Does safari currently support onerror?
If not, is there a workaround?
Yes, Safari does support window.onerror
with the function signature you posted: function(errorMsg, url, line)
, presumably since about 2011 when webkit added it.
However it does not currently support the new signature which includes the stack trace and column number: function(errorMsg, url, line, column, errorObject)
. This appears to be in the works, however: https://bugs.webkit.org/show_bug.cgi?id=55092
Firefox and Chrome already support the new syntax:
https://bugzilla.mozilla.org/show_bug.cgi?id=355430
https://code.google.com/p/chromium/issues/detail?id=147127
All major browsers now support the syntax function(errorMsg, url, line, column, errorObject)
. For more info see the article: https://blog.sentry.io/2016/01/04/client-javascript-reporting-window-onerror