From 7d360c05ecfaa47e44b856278146f53d8a6b7057 Mon Sep 17 00:00:00 2001 From: Michael Dellanoce Date: Mon, 27 Nov 2023 10:09:20 -0500 Subject: [PATCH] use native add/removeEventListener when zone.js is present --- packages/rrweb/src/utils.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/rrweb/src/utils.ts b/packages/rrweb/src/utils.ts index 5aa443561a..a02a1aa5b9 100644 --- a/packages/rrweb/src/utils.ts +++ b/packages/rrweb/src/utils.ts @@ -35,6 +35,10 @@ export function getZoneSymbol(symbolName: string): T { export const nativeSetTimeout = getZoneSymbol('setTimeout'); +export const nativeAddEventListener = + getZoneSymbol('addEventListener'); +export const nativeRemoveEventListener = + getZoneSymbol('removeEventListener'); export function on( type: string, @@ -42,8 +46,8 @@ export function on( target: Document | IWindow = document, ): listenerHandler { const options = { capture: true, passive: true }; - target.addEventListener(type, fn, options); - return () => target.removeEventListener(type, fn, options); + nativeAddEventListener.call(target, type, fn, options); + return () => nativeRemoveEventListener.call(target, type, fn, options); } // https://github.com/rrweb-io/rrweb/pull/407