fix #469 try to get original MutationObserver
We found Angular's zone module will patch MutationObserver which make the browser hang in some scenarios. Reference: angular/angular#26948
This commit is contained in:
@@ -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(
|
||||
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user