Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Safari support javascript window.onerror?

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?

like image 971
user2932876 Avatar asked Oct 02 '22 11:10

user2932876


2 Answers

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

like image 99
Johann Avatar answered Oct 07 '22 19:10

Johann


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

like image 45
Konstantin Smolyanin Avatar answered Oct 07 '22 19:10

Konstantin Smolyanin