diff --git a/.changeset/wet-bottles-flash.md b/.changeset/wet-bottles-flash.md new file mode 100644 index 00000000..687ea7d0 --- /dev/null +++ b/.changeset/wet-bottles-flash.md @@ -0,0 +1,6 @@ +--- +"rrweb": patch +"@rrweb/utils": patch +--- + +fix: wujie monkeypatches ownerDocument diff --git a/packages/rrweb/src/utils.ts b/packages/rrweb/src/utils.ts index 13b15ec6..ef05dca5 100644 --- a/packages/rrweb/src/utils.ts +++ b/packages/rrweb/src/utils.ts @@ -532,14 +532,14 @@ export function getRootShadowHost(n: Node): Node { } export function shadowHostInDom(n: Node): boolean { - const doc = n.ownerDocument; + const doc = dom.ownerDocument(n); if (!doc) return false; const shadowHost = getRootShadowHost(n); return dom.contains(doc, shadowHost); } export function inDom(n: Node): boolean { - const doc = n.ownerDocument; + const doc = dom.ownerDocument(n); if (!doc) return false; return dom.contains(doc, n) || shadowHostInDom(n); } diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 94a8dc83..84106ca6 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -13,7 +13,13 @@ type BasePrototypeCache = { }; const testableAccessors = { - Node: ['childNodes', 'parentNode', 'parentElement', 'textContent'] as const, + Node: [ + 'childNodes', + 'parentNode', + 'parentElement', + 'textContent', + 'ownerDocument', + ] as const, ShadowRoot: ['host', 'styleSheets'] as const, Element: ['shadowRoot', 'querySelector', 'querySelectorAll'] as const, MutationObserver: [] as const, @@ -169,6 +175,10 @@ export function getUntaintedMethod< return untaintedMethod.bind(instance) as BasePrototypeCache[K][T]; } +export function ownerDocument(n: Node): Document | null { + return getUntaintedAccessor('Node', n, 'ownerDocument'); +} + export function childNodes(n: Node): NodeListOf { return getUntaintedAccessor('Node', n, 'childNodes'); } @@ -266,6 +276,7 @@ export function patch( } export default { + ownerDocument, childNodes, parentNode, parentElement,