Skip to content

Reasoning behind using window.onerror over window.addEventListener('error') #5786

Closed Answered by AbhiPrasad
simenbrekken-visma asked this question in Q&A
Discussion options

You must be logged in to vote

Hey! Super interesting question. I asked this to @kamilogorek on our internal slack, and I'll summarize his answer here:

Right now it doesn't make that much a difference (if any). If I recall correctly, it was due to the fact that we wanted to be registered first (that's one thing); although now it doesn't work with new event listeners, as onerror is just syntax sugar. However, onerror is necessary for other usecases, outside of the main SDK

Mainly, these use cases are so that we can access the event listener after they have been set, for things like our async loader.

// fails
window.addEventListener('error', () => {})
console.log(window.onerror)
// works
window.onerror = () => {}
console.

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@simenbrekken-visma
Comment options

@simenbrekken-visma
Comment options

@kamilogorek
Comment options

@chenxin1212
Comment options

@AbhiPrasad
Comment options

Answer selected by simenbrekken-visma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants