@@ -64,24 +64,21 @@ export function instrumentDOM(): void {
64
64
// could potentially prevent the event from bubbling up to our global listeners. This way, our handler are still
65
65
// guaranteed to fire at least once.)
66
66
[ '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
70
72
if ( ! proto || ! proto . hasOwnProperty || ! proto . hasOwnProperty ( 'addEventListener' ) ) {
71
73
return ;
72
74
}
73
75
74
76
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 {
81
78
if ( type === 'click' || type == 'keypress' ) {
82
79
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__ || { } ) ;
85
82
const handlerForType = ( handlers [ type ] = handlers [ type ] || { refCount : 0 } ) ;
86
83
87
84
if ( ! handlerForType . handler ) {
@@ -105,16 +102,10 @@ export function instrumentDOM(): void {
105
102
proto ,
106
103
'removeEventListener' ,
107
104
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 {
114
106
if ( type === 'click' || type == 'keypress' ) {
115
107
try {
116
- const el = this as InstrumentedElement ;
117
- const handlers = el . __sentry_instrumentation_handlers__ || { } ;
108
+ const handlers = this . __sentry_instrumentation_handlers__ || { } ;
118
109
const handlerForType = handlers [ type ] ;
119
110
120
111
if ( handlerForType ) {
@@ -128,7 +119,7 @@ export function instrumentDOM(): void {
128
119
129
120
// If there are no longer any custom handlers of any type on this element, cleanup everything.
130
121
if ( Object . keys ( handlers ) . length === 0 ) {
131
- delete el . __sentry_instrumentation_handlers__ ;
122
+ delete this . __sentry_instrumentation_handlers__ ;
132
123
}
133
124
}
134
125
} catch ( e ) {
0 commit comments