Is there a way to try / catch the whole page dynamically?

I have a page where cryptic JavaScript errors appear. They seem to come from the application we use and do not own the source. I am working on a real solution to this problem, but tomorrow we have a demo, and I was wondering if there is a way to just suppress JS errors on the page (for example, wrapping all javascript components in a giant catch attempt).

+7
source share
1 answer

You can add a window.onerror event handler. In this case, all errors that occur inside the window will be redirected to the handler of this event. (I tested this in Firefox and it worked, but I had problems with it in Chrome. My installation of Chrome is rather confusing, so this may be a problem, but there are Chromium errors that relate to this problem: error # 7771 and error # 8939 )

window.onerror = function (msg, url, line) { alert("Error on line " + line + " in " + url + ":\n" + msg); // return true to prevent browser from displaying error return true; } 
+9
source

All Articles