@@ -96,8 +96,7 @@ const _browserApiErrorsIntegration = ((options: Partial<BrowserApiErrorsOptions>
9696export const browserApiErrorsIntegration = defineIntegration ( _browserApiErrorsIntegration ) ;
9797
9898function _wrapTimeFunction ( original : ( ) => void ) : ( ) => number {
99- // eslint-disable-next-line @typescript-eslint/no-explicit-any
100- return function ( this : any , ...args : any [ ] ) : number {
99+ return function ( this : unknown , ...args : unknown [ ] ) : number {
101100 const originalCallback = args [ 0 ] ;
102101 args [ 0 ] = wrap ( originalCallback , {
103102 mechanism : {
@@ -110,11 +109,8 @@ function _wrapTimeFunction(original: () => void): () => number {
110109 } ;
111110}
112111
113- // eslint-disable-next-line @typescript-eslint/no-explicit-any
114- function _wrapRAF ( original : any ) : ( callback : ( ) => void ) => any {
115- // eslint-disable-next-line @typescript-eslint/no-explicit-any
116- return function ( this : any , callback : ( ) => void ) : ( ) => void {
117- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
112+ function _wrapRAF ( original : ( ) => void ) : ( callback : ( ) => void ) => unknown {
113+ return function ( this : unknown , callback : ( ) => void ) : ( ) => void {
118114 return original . apply ( this , [
119115 wrap ( callback , {
120116 mechanism : {
@@ -131,16 +127,14 @@ function _wrapRAF(original: any): (callback: () => void) => any {
131127}
132128
133129function _wrapXHR ( originalSend : ( ) => void ) : ( ) => void {
134- // eslint-disable-next-line @typescript-eslint/no-explicit-any
135- return function ( this : XMLHttpRequest , ...args : any [ ] ) : void {
130+ return function ( this : XMLHttpRequest , ...args : unknown [ ] ) : void {
136131 // eslint-disable-next-line @typescript-eslint/no-this-alias
137132 const xhr = this ;
138133 const xmlHttpRequestProps : XMLHttpRequestProp [ ] = [ 'onload' , 'onerror' , 'onprogress' , 'onreadystatechange' ] ;
139134
140135 xmlHttpRequestProps . forEach ( prop => {
141136 if ( prop in xhr && typeof xhr [ prop ] === 'function' ) {
142- // eslint-disable-next-line @typescript-eslint/no-explicit-any
143- fill ( xhr , prop , function ( original : WrappedFunction ) : ( ) => any {
137+ fill ( xhr , prop , function ( original ) {
144138 const wrapOptions = {
145139 mechanism : {
146140 data : {
@@ -169,13 +163,11 @@ function _wrapXHR(originalSend: () => void): () => void {
169163}
170164
171165function _wrapEventTarget ( target : string ) : void {
172- // eslint-disable-next-line @typescript-eslint/no-explicit-any
173- const globalObject = WINDOW as { [ key : string ] : any } ;
174- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
175- const proto = globalObject [ target ] && globalObject [ target ] . prototype ;
166+ const globalObject = WINDOW as unknown as Record < string , { prototype ?: object } > ;
167+ const targetObj = globalObject [ target ] ;
168+ const proto = targetObj && targetObj . prototype ;
176169
177- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
178- if ( ! proto || ! proto . hasOwnProperty || ! proto . hasOwnProperty ( 'addEventListener' ) ) {
170+ if ( ! proto || Object . prototype . hasOwnProperty . call ( proto , 'addEventListener' ) ) {
179171 return ;
180172 }
181173
@@ -185,8 +177,7 @@ function _wrapEventTarget(target: string): void {
185177 options ?: boolean | AddEventListenerOptions ,
186178 ) => void {
187179 return function (
188- // eslint-disable-next-line @typescript-eslint/no-explicit-any
189- this : any ,
180+ this : unknown ,
190181 eventName : string ,
191182 fn : EventListenerObject ,
192183 options ?: boolean | AddEventListenerOptions ,
@@ -217,8 +208,7 @@ function _wrapEventTarget(target: string): void {
217208
218209 return original . apply ( this , [
219210 eventName ,
220- // eslint-disable-next-line @typescript-eslint/no-explicit-any
221- wrap ( fn as any as WrappedFunction , {
211+ wrap ( fn , {
222212 mechanism : {
223213 data : {
224214 function : 'addEventListener' ,
@@ -234,48 +224,45 @@ function _wrapEventTarget(target: string): void {
234224 } ;
235225 } ) ;
236226
237- fill (
238- proto ,
239- 'removeEventListener' ,
240- function (
241- originalRemoveEventListener : ( ) => void ,
242- // eslint-disable-next-line @typescript-eslint/no-explicit-any
243- ) : ( this : any , eventName : string , fn : EventListenerObject , options ?: boolean | EventListenerOptions ) => ( ) => void {
244- return function (
245- // eslint-disable-next-line @typescript-eslint/no-explicit-any
246- this : any ,
247- eventName : string ,
248- fn : EventListenerObject ,
249- options ?: boolean | EventListenerOptions ,
250- ) : ( ) => void {
251- /**
252- * There are 2 possible scenarios here:
253- *
254- * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
255- * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
256- * as a pass-through, and call original `removeEventListener` with it.
257- *
258- * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
259- * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
260- * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
261- * in order for us to make a distinction between wrapped/non-wrapped functions possible.
262- * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
263- *
264- * When someone adds a handler prior to initialization, and then do it again, but after,
265- * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
266- * to get rid of the initial handler and it'd stick there forever.
267- */
268- const wrappedEventHandler = fn as unknown as WrappedFunction ;
269- try {
270- const originalEventHandler = wrappedEventHandler && wrappedEventHandler . __sentry_wrapped__ ;
271- if ( originalEventHandler ) {
272- originalRemoveEventListener . call ( this , eventName , originalEventHandler , options ) ;
273- }
274- } catch ( e ) {
275- // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
227+ fill ( proto , 'removeEventListener' , function ( originalRemoveEventListener : ( ) => void , ) : (
228+ this : unknown ,
229+ eventName : string ,
230+ fn : EventListenerObject ,
231+ options ?: boolean | EventListenerOptions ,
232+ ) => ( ) => void {
233+ return function (
234+ this : unknown ,
235+ eventName : string ,
236+ fn : EventListenerObject ,
237+ options ?: boolean | EventListenerOptions ,
238+ ) : ( ) => void {
239+ /**
240+ * There are 2 possible scenarios here:
241+ *
242+ * 1. Someone passes a callback, which was attached prior to Sentry initialization, or by using unmodified
243+ * method, eg. `document.addEventListener.call(el, name, handler). In this case, we treat this function
244+ * as a pass-through, and call original `removeEventListener` with it.
245+ *
246+ * 2. Someone passes a callback, which was attached after Sentry was initialized, which means that it was using
247+ * our wrapped version of `addEventListener`, which internally calls `wrap` helper.
248+ * This helper "wraps" whole callback inside a try/catch statement, and attached appropriate metadata to it,
249+ * in order for us to make a distinction between wrapped/non-wrapped functions possible.
250+ * If a function was wrapped, it has additional property of `__sentry_wrapped__`, holding the handler.
251+ *
252+ * When someone adds a handler prior to initialization, and then do it again, but after,
253+ * then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
254+ * to get rid of the initial handler and it'd stick there forever.
255+ */
256+ const wrappedEventHandler = fn as unknown as WrappedFunction ;
257+ try {
258+ const originalEventHandler = wrappedEventHandler && wrappedEventHandler . __sentry_wrapped__ ;
259+ if ( originalEventHandler ) {
260+ originalRemoveEventListener . call ( this , eventName , originalEventHandler , options ) ;
276261 }
277- return originalRemoveEventListener . call ( this , eventName , wrappedEventHandler , options ) ;
278- } ;
279- } ,
280- ) ;
262+ } catch ( e ) {
263+ // ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
264+ }
265+ return originalRemoveEventListener . call ( this , eventName , wrappedEventHandler , options ) ;
266+ } ;
267+ } ) ;
281268}
0 commit comments