Capture page exceptions,Is assigning a function to window.onerror preferable to window.addEventListener('error', callback)? #7542
Replies: 1 comment
-
Hey @huanghairong2312, we've talked about why we prefer |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Capture page exceptions in Sentry source code,Assigning a function to window.onerror seems like a pretty straightforward way to start handling errors in the code on a page. However, it's important to make sure you're not overwriting a pre-existing error handler, so it's usual practice to maintain a reference to the previous value and call it as part of your new function. As an example:
My question is: Why don't adding an event handler for the 'error' event instead? That allows multiple functions to be called when one of those events is triggered, and doesn't require awkwardly maintaining references to other error handlers.
During the process of using Sentry, we accidentally assigned a null value to widnow.oneerror, resulting in the page being unable to catch exceptions. use window.addEventListener is better ?
Beta Was this translation helpful? Give feedback.
All reactions