@@ -172,18 +172,16 @@ function _wrapEventTarget(target: string): void {
172
172
}
173
173
174
174
fill ( proto , 'addEventListener' , function ( original : VoidFunction , ) : (
175
- eventName : string ,
176
- fn : EventListenerObject ,
177
- options ?: boolean | AddEventListenerOptions ,
175
+ ...args : Parameters < typeof WINDOW . addEventListener >
178
176
) => void {
179
177
return function (
180
178
this : unknown ,
181
- eventName : string ,
182
- fn : EventListenerObject ,
183
- options ?: boolean | AddEventListenerOptions ,
179
+ eventName ,
180
+ fn ,
181
+ options ,
184
182
) : ( eventName : string , fn : EventListenerObject , capture ?: boolean , secure ?: boolean ) => void {
185
183
try {
186
- if ( typeof fn . handleEvent === 'function' ) {
184
+ if ( isEventListenerObject ( fn ) ) {
187
185
// ESlint disable explanation:
188
186
// First, it is generally safe to call `wrap` with an unbound function. Furthermore, using `.bind()` would
189
187
// introduce a bug here, because bind returns a new function that doesn't have our
@@ -202,7 +200,7 @@ function _wrapEventTarget(target: string): void {
202
200
} ,
203
201
} ) ;
204
202
}
205
- } catch ( err ) {
203
+ } catch {
206
204
// can sometimes get 'Permission denied to access property "handle Event'
207
205
}
208
206
@@ -226,16 +224,9 @@ function _wrapEventTarget(target: string): void {
226
224
227
225
fill ( proto , 'removeEventListener' , function ( originalRemoveEventListener : ( ) => void , ) : (
228
226
this : unknown ,
229
- eventName : string ,
230
- fn : EventListenerObject ,
231
- options ?: boolean | EventListenerOptions ,
227
+ ...args : Parameters < typeof WINDOW . removeEventListener >
232
228
) => ( ) => void {
233
- return function (
234
- this : unknown ,
235
- eventName : string ,
236
- fn : EventListenerObject ,
237
- options ?: boolean | EventListenerOptions ,
238
- ) : ( ) => void {
229
+ return function ( this : unknown , eventName , fn , options ) : ( ) => void {
239
230
/**
240
231
* There are 2 possible scenarios here:
241
232
*
@@ -253,16 +244,19 @@ function _wrapEventTarget(target: string): void {
253
244
* then we have to detach both of them. Otherwise, if we'd detach only wrapped one, it'd be impossible
254
245
* to get rid of the initial handler and it'd stick there forever.
255
246
*/
256
- const wrappedEventHandler = fn as unknown as WrappedFunction ;
257
247
try {
258
- const originalEventHandler = wrappedEventHandler && wrappedEventHandler . __sentry_wrapped__ ;
248
+ const originalEventHandler = ( fn as WrappedFunction ) . __sentry_wrapped__ ;
259
249
if ( originalEventHandler ) {
260
250
originalRemoveEventListener . call ( this , eventName , originalEventHandler , options ) ;
261
251
}
262
252
} catch ( e ) {
263
253
// ignore, accessing __sentry_wrapped__ will throw in some Selenium environments
264
254
}
265
- return originalRemoveEventListener . call ( this , eventName , wrappedEventHandler , options ) ;
255
+ return originalRemoveEventListener . call ( this , eventName , fn , options ) ;
266
256
} ;
267
257
} ) ;
268
258
}
259
+
260
+ function isEventListenerObject ( obj : unknown ) : obj is EventListenerObject {
261
+ return typeof ( obj as EventListenerObject ) . handleEvent === 'function' ;
262
+ }
0 commit comments