From 6a6d036ee3532014db4b77fd5e269a7178d1d960 Mon Sep 17 00:00:00 2001 From: fukang wang Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] fix: wujie shadow root (#1763) * Fix wujie monkeypatches ownerDocument --------- Co-authored-by: wfk007 --- .changeset/wet-bottles-flash.md | 6 ++++++ packages/rrweb/src/utils.ts | 4 ++-- packages/utils/src/index.ts | 13 ++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .changeset/wet-bottles-flash.md 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,