@@ -64,24 +64,21 @@ export function instrumentDOM(): void {
6464 // could potentially prevent the event from bubbling up to our global listeners. This way, our handler are still
6565 // guaranteed to fire at least once.)
6666 [ 'EventTarget' , 'Node' ] . forEach ( ( target : string ) => {
67- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
68- const proto = ( WINDOW as any ) [ target ] && ( WINDOW as any ) [ target ] . prototype ;
69- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-prototype-builtins
67+ const globalObject = WINDOW as unknown as Record < string , { prototype ?: object } > ;
68+ const targetObj = globalObject [ target ] ;
69+ const proto = targetObj && targetObj . prototype ;
70+
71+ // eslint-disable-next-line no-prototype-builtins
7072 if ( ! proto || ! proto . hasOwnProperty || ! proto . hasOwnProperty ( 'addEventListener' ) ) {
7173 return ;
7274 }
7375
7476 fill ( proto , 'addEventListener' , function ( originalAddEventListener : AddEventListener ) : AddEventListener {
75- return function (
76- this : Element ,
77- type : string ,
78- listener : EventListenerOrEventListenerObject ,
79- options ?: boolean | AddEventListenerOptions ,
80- ) : AddEventListener {
77+ return function ( this : InstrumentedElement , type , listener , options ) : AddEventListener {
8178 if ( type === 'click' || type == 'keypress' ) {
8279 try {
83- const el = this as InstrumentedElement ;
84- const handlers = ( el . __sentry_instrumentation_handlers__ = el . __sentry_instrumentation_handlers__ || { } ) ;
80+ const handlers = ( this . __sentry_instrumentation_handlers__ =
81+ this . __sentry_instrumentation_handlers__ || { } ) ;
8582 const handlerForType = ( handlers [ type ] = handlers [ type ] || { refCount : 0 } ) ;
8683
8784 if ( ! handlerForType . handler ) {
@@ -105,16 +102,10 @@ export function instrumentDOM(): void {
105102 proto ,
106103 'removeEventListener' ,
107104 function ( originalRemoveEventListener : RemoveEventListener ) : RemoveEventListener {
108- return function (
109- this : Element ,
110- type : string ,
111- listener : EventListenerOrEventListenerObject ,
112- options ?: boolean | EventListenerOptions ,
113- ) : ( ) => void {
105+ return function ( this : InstrumentedElement , type , listener , options ) : ( ) => void {
114106 if ( type === 'click' || type == 'keypress' ) {
115107 try {
116- const el = this as InstrumentedElement ;
117- const handlers = el . __sentry_instrumentation_handlers__ || { } ;
108+ const handlers = this . __sentry_instrumentation_handlers__ || { } ;
118109 const handlerForType = handlers [ type ] ;
119110
120111 if ( handlerForType ) {
@@ -128,7 +119,7 @@ export function instrumentDOM(): void {
128119
129120 // If there are no longer any custom handlers of any type on this element, cleanup everything.
130121 if ( Object . keys ( handlers ) . length === 0 ) {
131- delete el . __sentry_instrumentation_handlers__ ;
122+ delete this . __sentry_instrumentation_handlers__ ;
132123 }
133124 }
134125 } catch ( e ) {
0 commit comments