Skip to content

Commit

Permalink
fix rrweb-io#469 try to get original MutationObserver
Browse files Browse the repository at this point in the history
We found Angular's zone module will patch MutationObserver which
make the browser hang in some scenarios.
Reference: angular/angular#26948
  • Loading branch information
Yuyz0112 authored and eoghanmurray committed Feb 22, 2021
1 parent d5d0053 commit 4e9dc36
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ import {
import MutationBuffer from './mutation';
import { stringify } from './stringify';

type WindowWithAngularZone = Window & {
Zone?: {
__symbol__?: (key: string) => string;
};
};

export const mutationBuffer = new MutationBuffer();

function initMutationObserver(
Expand All @@ -65,7 +71,22 @@ function initMutationObserver(
recordCanvas,
slimDOMOptions,
);
const observer = new MutationObserver(
let mutationBufferCtor = window.MutationObserver;
const angularZoneSymbol = (window as WindowWithAngularZone)?.Zone?.__symbol__?.(
'MutationObserver',
);
if (
angularZoneSymbol &&
((window as unknown) as Record<string, typeof MutationObserver>)[
angularZoneSymbol
]
) {
mutationBufferCtor = ((window as unknown) as Record<
string,
typeof MutationObserver
>)[angularZoneSymbol];
}
const observer = new mutationBufferCtor(
mutationBuffer.processMutations.bind(mutationBuffer),
);
observer.observe(document, {
Expand Down

0 comments on commit 4e9dc36

Please sign in to comment.