@@ -64,24 +64,20 @@ 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
70- if ( ! proto || ! proto . hasOwnProperty || ! proto . hasOwnProperty ( 'addEventListener' ) ) {
67+ const globalObject = WINDOW as unknown as Record < string , { prototype ?: object } > ;
68+ const targetObj = globalObject [ target ] ;
69+ const proto = targetObj && targetObj . prototype ;
70+
71+ if ( ! proto || Object . prototype . hasOwnProperty . call ( proto , 'addEventListener' ) ) {
7172 return ;
7273 }
7374
7475 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 {
76+ return function ( this : InstrumentedElement , type , listener , options ) : AddEventListener {
8177 if ( type === 'click' || type == 'keypress' ) {
8278 try {
83- const el = this as InstrumentedElement ;
84- const handlers = ( el . __sentry_instrumentation_handlers__ = el . __sentry_instrumentation_handlers__ || { } ) ;
79+ const handlers = ( this . __sentry_instrumentation_handlers__ =
80+ this . __sentry_instrumentation_handlers__ || { } ) ;
8581 const handlerForType = ( handlers [ type ] = handlers [ type ] || { refCount : 0 } ) ;
8682
8783 if ( ! handlerForType . handler ) {
@@ -105,16 +101,10 @@ export function instrumentDOM(): void {
105101 proto ,
106102 'removeEventListener' ,
107103 function ( originalRemoveEventListener : RemoveEventListener ) : RemoveEventListener {
108- return function (
109- this : Element ,
110- type : string ,
111- listener : EventListenerOrEventListenerObject ,
112- options ?: boolean | EventListenerOptions ,
113- ) : ( ) => void {
104+ return function ( this : InstrumentedElement , type , listener , options ) : ( ) => void {
114105 if ( type === 'click' || type == 'keypress' ) {
115106 try {
116- const el = this as InstrumentedElement ;
117- const handlers = el . __sentry_instrumentation_handlers__ || { } ;
107+ const handlers = this . __sentry_instrumentation_handlers__ || { } ;
118108 const handlerForType = handlers [ type ] ;
119109
120110 if ( handlerForType ) {
@@ -128,7 +118,7 @@ export function instrumentDOM(): void {
128118
129119 // If there are no longer any custom handlers of any type on this element, cleanup everything.
130120 if ( Object . keys ( handlers ) . length === 0 ) {
131- delete el . __sentry_instrumentation_handlers__ ;
121+ delete this . __sentry_instrumentation_handlers__ ;
132122 }
133123 }
134124 } catch ( e ) {
0 commit comments