@@ -109,7 +109,7 @@ export class TryCatch implements Integration {
109
109
/** JSDoc */
110
110
function _wrapTimeFunction ( original : ( ) => void ) : ( ) => number {
111
111
// eslint-disable-next-line @typescript-eslint/no-explicit-any
112
- return function ( this : any , ...args : any [ ] ) : number {
112
+ return function ( this : any , ...args : any [ ] ) : number {
113
113
const originalCallback = args [ 0 ] ;
114
114
args [ 0 ] = wrap ( originalCallback , {
115
115
mechanism : {
@@ -126,7 +126,7 @@ function _wrapTimeFunction(original: () => void): () => number {
126
126
// eslint-disable-next-line @typescript-eslint/no-explicit-any
127
127
function _wrapRAF ( original : any ) : ( callback : ( ) => void ) => any {
128
128
// eslint-disable-next-line @typescript-eslint/no-explicit-any
129
- return function ( this : any , callback : ( ) => void ) : ( ) => void {
129
+ return function ( this : any , callback : ( ) => void ) : ( ) => void {
130
130
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
131
131
return original . call (
132
132
this ,
@@ -147,15 +147,15 @@ function _wrapRAF(original: any): (callback: () => void) => any {
147
147
/** JSDoc */
148
148
function _wrapXHR ( originalSend : ( ) => void ) : ( ) => void {
149
149
// eslint-disable-next-line @typescript-eslint/no-explicit-any
150
- return function ( this : XMLHttpRequest , ...args : any [ ] ) : void {
150
+ return function ( this : XMLHttpRequest , ...args : any [ ] ) : void {
151
151
// eslint-disable-next-line @typescript-eslint/no-this-alias
152
152
const xhr = this ;
153
153
const xmlHttpRequestProps : XMLHttpRequestProp [ ] = [ 'onload' , 'onerror' , 'onprogress' , 'onreadystatechange' ] ;
154
154
155
155
xmlHttpRequestProps . forEach ( prop => {
156
156
if ( prop in xhr && typeof xhr [ prop ] === 'function' ) {
157
157
// eslint-disable-next-line @typescript-eslint/no-explicit-any
158
- fill ( xhr , prop , function ( original : WrappedFunction ) : ( ) => any {
158
+ fill ( xhr , prop , function ( original : WrappedFunction ) : ( ) => any {
159
159
const wrapOptions = {
160
160
mechanism : {
161
161
data : {
@@ -195,10 +195,12 @@ function _wrapEventTarget(target: string): void {
195
195
return ;
196
196
}
197
197
198
- fill ( proto , 'addEventListener' , function (
199
- original : ( ) => void ,
200
- ) : ( eventName : string , fn : EventListenerObject , options ?: boolean | AddEventListenerOptions ) => void {
201
- return function (
198
+ fill ( proto , 'addEventListener' , function ( original : ( ) => void ) : (
199
+ eventName : string ,
200
+ fn : EventListenerObject ,
201
+ options ?: boolean | AddEventListenerOptions ,
202
+ ) => void {
203
+ return function (
202
204
// eslint-disable-next-line @typescript-eslint/no-explicit-any
203
205
this : any ,
204
206
eventName : string ,
@@ -227,7 +229,7 @@ function _wrapEventTarget(target: string): void {
227
229
this ,
228
230
eventName ,
229
231
// eslint-disable-next-line @typescript-eslint/no-explicit-any
230
- wrap ( ( fn as any ) as WrappedFunction , {
232
+ wrap ( fn as any as WrappedFunction , {
231
233
mechanism : {
232
234
data : {
233
235
function : 'addEventListener' ,
@@ -243,44 +245,48 @@ function _wrapEventTarget(target: string): void {
243
245
} ;
244
246
} ) ;
245
247
246
- fill ( proto , 'removeEventListener' , function (
247
- originalRemoveEventListener : ( ) => void ,
248
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
249
- ) : ( this : any , eventName : string , fn : EventListenerObject , options ?: boolean | EventListenerOptions ) => ( ) => void {
250
- return function (
248
+ fill (
249
+ proto ,
250
+ 'removeEventListener' ,
251
+ function (
252
+ originalRemoveEventListener : ( ) => void ,
251
253
// eslint-disable-next-line @typescript-eslint/no-explicit-any
252
- this : any ,
253
- eventName : string ,
254
- fn : EventListenerObject ,
255
- options ?: boolean | EventListenerOptions ,
256
- ) : ( ) => void {
257
- /**
258
- * There are 2 possible scenarios here:
259
- *
260
- * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
261
- * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
262
- * as a pass-through, and call original `removeEventListener` with it.
263
- *
264
- * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
265
- * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
266
- * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
267
- * in order for us to make a distinction between wrapped/non-wrapped functions possible.
268
- * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
269
- *
270
- * When someone adds a handler prior to initialization, and then do it again, but after,
271
- * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
272
- * to get rid of the initial handler and it'd stick there forever.
273
- */
274
- const wrappedEventHandler = ( fn as unknown ) as WrappedFunction ;
275
- try {
276
- const originalEventHandler = wrappedEventHandler && wrappedEventHandler . __sentry_wrapped__ ;
277
- if ( originalEventHandler ) {
278
- originalRemoveEventListener . call ( this , eventName , originalEventHandler , options ) ;
254
+ ) : ( this : any , eventName : string , fn : EventListenerObject , options ?: boolean | EventListenerOptions ) => ( ) => void {
255
+ return function (
256
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
257
+ this : any ,
258
+ eventName : string ,
259
+ fn : EventListenerObject ,
260
+ options ?: boolean | EventListenerOptions ,
261
+ ) : ( ) => void {
262
+ /**
263
+ * There are 2 possible scenarios here:
264
+ *
265
+ * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
266
+ * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
267
+ * as a pass-through, and call original `removeEventListener` with it.
268
+ *
269
+ * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
270
+ * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
271
+ * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
272
+ * in order for us to make a distinction between wrapped/non-wrapped functions possible.
273
+ * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
274
+ *
275
+ * When someone adds a handler prior to initialization, and then do it again, but after,
276
+ * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
277
+ * to get rid of the initial handler and it'd stick there forever.
278
+ */
279
+ const wrappedEventHandler = fn as unknown as WrappedFunction ;
280
+ try {
281
+ const originalEventHandler = wrappedEventHandler && wrappedEventHandler . __sentry_wrapped__ ;
282
+ if ( originalEventHandler ) {
283
+ originalRemoveEventListener . call ( this , eventName , originalEventHandler , options ) ;
284
+ }
285
+ } catch ( e ) {
286
+ // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
279
287
}
280
- } catch ( e ) {
281
- // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
282
- }
283
- return originalRemoveEventListener . call ( this , eventName , wrappedEventHandler , options ) ;
284
- } ;
285
- } ) ;
288
+ return originalRemoveEventListener . call ( this , eventName , wrappedEventHandler , options ) ;
289
+ } ;
290
+ } ,
291
+ ) ;
286
292
}
0 commit comments