File tree 4 files changed +22
-6
lines changed
4 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 2
2
3
3
## Unreleased
4
4
5
+ - [ browser] fix: Handle PromiseRejectionEvent-like CustomEvents
6
+
5
7
## 5.12.3
6
8
7
9
- [ apm] fix: Remove undefined keys from trace.context
Original file line number Diff line number Diff line change @@ -138,8 +138,22 @@ export class GlobalHandlers implements Integration {
138
138
139
139
this . _global . onunhandledrejection = function ( e : any ) : boolean {
140
140
let error = e ;
141
+
142
+ // dig the object of the rejection out of known event types
141
143
try {
142
- error = e && 'reason' in e ? e . reason : e ;
144
+ // PromiseRejectionEvents store the object of the rejection under 'reason'
145
+ // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
146
+ if ( 'reason' in e ) {
147
+ error = e . reason ;
148
+ }
149
+ // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
150
+ // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
151
+ // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
152
+ // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
153
+ // https://github.com/getsentry/sentry-javascript/issues/2380
154
+ else if ( 'detail' in e && 'reason' in e . detail ) {
155
+ error = e . detail . reason ;
156
+ }
143
157
} catch ( _oO ) {
144
158
// no-empty
145
159
}
Original file line number Diff line number Diff line change 200
200
201
201
// Do the same store/queue/call operations for `onunhandledrejection` event
202
202
var _oldOnunhandledrejection = _window [ _onunhandledrejection ] ;
203
- _window [ _onunhandledrejection ] = function ( exception ) {
203
+ _window [ _onunhandledrejection ] = function ( e ) {
204
204
queue ( {
205
- p : exception . reason
205
+ p : 'reason' in e ? e . reason : 'detail' in e && 'reason' in e . detail ? e . detail . reason : e
206
206
} ) ;
207
207
if ( _oldOnunhandledrejection ) _oldOnunhandledrejection . apply ( _window , arguments ) ;
208
208
} ;
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ export class Dedupe implements Integration {
61
61
const currentMessage = currentEvent . message ;
62
62
const previousMessage = previousEvent . message ;
63
63
64
- // If no event has a message, they were both exceptions, so bail out
64
+ // If neither event has a message property , they were both exceptions, so bail out
65
65
if ( ! currentMessage && ! previousMessage ) {
66
66
return false ;
67
67
}
@@ -108,7 +108,7 @@ export class Dedupe implements Integration {
108
108
let currentFrames = this . _getFramesFromEvent ( currentEvent ) ;
109
109
let previousFrames = this . _getFramesFromEvent ( previousEvent ) ;
110
110
111
- // If no event has a fingerprint , they are assumed to be the same
111
+ // If neither event has a stacktrace , they are assumed to be the same
112
112
if ( ! currentFrames && ! previousFrames ) {
113
113
return true ;
114
114
}
@@ -178,7 +178,7 @@ export class Dedupe implements Integration {
178
178
let currentFingerprint = currentEvent . fingerprint ;
179
179
let previousFingerprint = previousEvent . fingerprint ;
180
180
181
- // If no event has a fingerprint, they are assumed to be the same
181
+ // If neither event has a fingerprint, they are assumed to be the same
182
182
if ( ! currentFingerprint && ! previousFingerprint ) {
183
183
return true ;
184
184
}
You can’t perform that action at this time.
0 commit comments