getsentry / getsentry/sentry-javascript

GlobalHandlers: Use event handlers instead of monkey-patching `window.onerror`

Đang mở
#17,217 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Improvement
Ngôn ngữ chính
TypeScript
Star
8.7k
Fork
1.8k
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
515

Mô tả

### Description

Today, our `globalHandlersIntegration` monkey-patches `window.onerror` and `window.onunhandledrejection` directly. While this worked generally fine, it has the disadvantage that any party could come in with an improper monkey patch and remove Sentry form the listener chain.

Instead, we could use `window.addEventListener('error')` (same for unhanded rejection).

While we get the same data, this has the advantage that the SDK can't be removed by accident.

Compatibility-wise, using event handlers [should be fine](https://caniuse.com/?search=addeventlistener).

Which leaves us with the thing we need to investigate carefully: Compatibility with our loader script.
This is the reason why we currently still use `onerror`:

https://github.com/getsentry/sentry-javascript/blob/faada7ca942403bba2627208a7e5a4516606dbeb/packages/core/src/instrument/globalError.ts#L22-L23

However, we're not (yet) sure if this is actually a concern. Whatever we do here, we need to ensure that behaviour for the loader doesn't change and vice versa.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.