Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- [browser] fix: Handle PromiseRejectionEvent-like CustomEvents

## 5.12.3

- [apm] fix: Remove undefined keys from trace.context
Expand Down
16 changes: 15 additions & 1 deletion packages/browser/src/integrations/globalhandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,22 @@ export class GlobalHandlers implements Integration {

this._global.onunhandledrejection = function(e: any): boolean {
let error = e;

// dig the object of the rejection out of known event types
try {
error = e && 'reason' in e ? e.reason : e;
// PromiseRejectionEvents store the object of the rejection under 'reason'
// see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
if ('reason' in e) {
error = e.reason;
}
// something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
// to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
// the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
// see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
// https://github.com/getsentry/sentry-javascript/issues/2380
else if ('detail' in e && 'reason' in e.detail) {
error = e.detail.reason;
}
} catch (_oO) {
// no-empty
}
Expand Down
4 changes: 2 additions & 2 deletions packages/browser/src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@

// Do the same store/queue/call operations for `onunhandledrejection` event
var _oldOnunhandledrejection = _window[_onunhandledrejection];
_window[_onunhandledrejection] = function(exception) {
_window[_onunhandledrejection] = function(e) {
queue({
p: exception.reason
p: 'reason' in e ? e.reason : 'detail' in e && 'reason' in e.detail ? e.detail.reason : e
});
if (_oldOnunhandledrejection) _oldOnunhandledrejection.apply(_window, arguments);
};
Expand Down
6 changes: 3 additions & 3 deletions packages/integrations/src/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class Dedupe implements Integration {
const currentMessage = currentEvent.message;
const previousMessage = previousEvent.message;

// If no event has a message, they were both exceptions, so bail out
// If neither event has a message property, they were both exceptions, so bail out
if (!currentMessage && !previousMessage) {
return false;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ export class Dedupe implements Integration {
let currentFrames = this._getFramesFromEvent(currentEvent);
let previousFrames = this._getFramesFromEvent(previousEvent);

// If no event has a fingerprint, they are assumed to be the same
// If neither event has a stacktrace, they are assumed to be the same
if (!currentFrames && !previousFrames) {
return true;
}
Expand Down Expand Up @@ -178,7 +178,7 @@ export class Dedupe implements Integration {
let currentFingerprint = currentEvent.fingerprint;
let previousFingerprint = previousEvent.fingerprint;

// If no event has a fingerprint, they are assumed to be the same
// If neither event has a fingerprint, they are assumed to be the same
if (!currentFingerprint && !previousFingerprint) {
return true;
}
Expand Down