@@ -109,7 +109,7 @@ export class TryCatch implements Integration {
109109/** JSDoc */
110110function _wrapTimeFunction ( original : ( ) => void ) : ( ) => number {
111111 // 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 {
113113 const originalCallback = args [ 0 ] ;
114114 args [ 0 ] = wrap ( originalCallback , {
115115 mechanism : {
@@ -126,7 +126,7 @@ function _wrapTimeFunction(original: () => void): () => number {
126126// eslint-disable-next-line @typescript-eslint/no-explicit-any
127127function _wrapRAF ( original : any ) : ( callback : ( ) => void ) => any {
128128 // 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 {
130130 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
131131 return original . call (
132132 this ,
@@ -147,15 +147,15 @@ function _wrapRAF(original: any): (callback: () => void) => any {
147147/** JSDoc */
148148function _wrapXHR ( originalSend : ( ) => void ) : ( ) => void {
149149 // 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 {
151151 // eslint-disable-next-line @typescript-eslint/no-this-alias
152152 const xhr = this ;
153153 const xmlHttpRequestProps : XMLHttpRequestProp [ ] = [ 'onload' , 'onerror' , 'onprogress' , 'onreadystatechange' ] ;
154154
155155 xmlHttpRequestProps . forEach ( prop => {
156156 if ( prop in xhr && typeof xhr [ prop ] === 'function' ) {
157157 // 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 {
159159 const wrapOptions = {
160160 mechanism : {
161161 data : {
@@ -195,10 +195,12 @@ function _wrapEventTarget(target: string): void {
195195 return ;
196196 }
197197
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 (
202204 // eslint-disable-next-line @typescript-eslint/no-explicit-any
203205 this : any ,
204206 eventName : string ,
@@ -227,7 +229,7 @@ function _wrapEventTarget(target: string): void {
227229 this ,
228230 eventName ,
229231 // eslint-disable-next-line @typescript-eslint/no-explicit-any
230- wrap ( ( fn as any ) as WrappedFunction , {
232+ wrap ( fn as any as WrappedFunction , {
231233 mechanism : {
232234 data : {
233235 function : 'addEventListener' ,
@@ -243,44 +245,48 @@ function _wrapEventTarget(target: string): void {
243245 } ;
244246 } ) ;
245247
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 ,
251253 // 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
279287 }
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+ ) ;
286292}
0 commit comments