Skip to content

Commit

Permalink
use native add/removeEventListener when zone.js is present
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellanoce committed Nov 27, 2023
1 parent c34b381 commit 7d360c0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,19 @@ export function getZoneSymbol<T>(symbolName: string): T {

export const nativeSetTimeout =
getZoneSymbol<typeof window.setTimeout>('setTimeout');
export const nativeAddEventListener =
getZoneSymbol<typeof window.addEventListener>('addEventListener');
export const nativeRemoveEventListener =
getZoneSymbol<typeof window.removeEventListener>('removeEventListener');

export function on(
type: string,
fn: EventListenerOrEventListenerObject,
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
Expand Down

0 comments on commit 7d360c0

Please sign in to comment.