From 34c74445ba8f897246ceb720952ef5462303a71c Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Thu, 4 Feb 2021 15:00:14 +0800 Subject: [PATCH] read __rrMutationObserver from window --- .gitignore | 2 ++ package.json | 2 +- src/record/mutation.ts | 2 +- src/record/observer.ts | 15 ++++++++++++++- yarn.lock | 8 ++++---- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index ceafb636..de1069e3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ es lib temp + +*.log diff --git a/package.json b/package.json index 7331ac48..bb860a7a 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,6 @@ "@xstate/fsm": "^1.4.0", "fflate": "^0.4.4", "mitt": "^1.1.3", - "rrweb-snapshot": "^1.0.3" + "rrweb-snapshot": "^1.0.4" } } diff --git a/src/record/mutation.ts b/src/record/mutation.ts index b4bbf271..bc89342f 100644 --- a/src/record/mutation.ts +++ b/src/record/mutation.ts @@ -112,6 +112,7 @@ function isINode(n: Node | INode): n is INode { */ export default class MutationBuffer { private frozen: boolean = false; + private locked: boolean = false; private texts: textCursor[] = []; private attributes: attributeCursor[] = []; @@ -195,7 +196,6 @@ export default class MutationBuffer { }; public emit = () => { - if (this.frozen || this.locked) { return; } diff --git a/src/record/observer.ts b/src/record/observer.ts index a6afce3e..13dea21c 100644 --- a/src/record/observer.ts +++ b/src/record/observer.ts @@ -44,6 +44,9 @@ import { import MutationBuffer from './mutation'; import { stringify } from './stringify'; +type WindowWithStoredMutationObserver = Window & { + __rrMutationObserver?: MutationObserver; +}; type WindowWithAngularZone = Window & { Zone?: { __symbol__?: (key: string) => string; @@ -71,7 +74,17 @@ function initMutationObserver( recordCanvas, slimDOMOptions, ); - let mutationBufferCtor = window.MutationObserver; + let mutationBufferCtor = + window.MutationObserver || + /** + * Some websites may disable MutationObserver by removing it from the window object. + * If someone is using rrweb to build a browser extention or things like it, they + * could not change the website's code but can have an opportunity to inject some + * code before the website executing its JS logic. + * Then they can do this to store the native MutationObserver: + * window.__rrMutationObserver = MutationObserver + */ + (window as WindowWithStoredMutationObserver).__rrMutationObserver; const angularZoneSymbol = (window as WindowWithAngularZone)?.Zone?.__symbol__?.( 'MutationObserver', ); diff --git a/yarn.lock b/yarn.lock index c9643380..17790fd7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2749,10 +2749,10 @@ rollup@^2.3.3: optionalDependencies: fsevents "~2.1.2" -rrweb-snapshot@^1.0.1: - version "1.0.2" - resolved "https://registry.npmjs.org/rrweb-snapshot/-/rrweb-snapshot-1.0.2.tgz#0338c9e00e24e86f8efb56cbdb293def7287f53c" - integrity sha512-QtWwK9fqNLn1wn7nupyy/BcTnMfl8rrtG6uQ0pC3xeXskVQ9GXuh/ulEpuzyVIVPszF/AvT4DjfWmwC5K6xusA== +rrweb-snapshot@^1.0.4: + version "1.0.4" + resolved "https://registry.yarnpkg.com/rrweb-snapshot/-/rrweb-snapshot-1.0.4.tgz#608acf0f066e4f72213109ee6bfe25d291e7eb0b" + integrity sha512-I9oeK+LPeFE8N8MT011gBLEb+3VjnU3TJNHphzqDu5XJLna8bvMx9tkTiyD9MOlVCX80Le/MwSBxoJMpCX9uQA== run-async@^2.2.0: version "2.4.1"