fix: wujie shadow root (#1763)
* Fix wujie monkeypatches ownerDocument --------- Co-authored-by: wfk007 <wfk007@users.noreply.github.com>
This commit is contained in:
6
.changeset/wet-bottles-flash.md
Normal file
6
.changeset/wet-bottles-flash.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"rrweb": patch
|
||||||
|
"@rrweb/utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: wujie monkeypatches ownerDocument
|
||||||
@@ -532,14 +532,14 @@ export function getRootShadowHost(n: Node): Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function shadowHostInDom(n: Node): boolean {
|
export function shadowHostInDom(n: Node): boolean {
|
||||||
const doc = n.ownerDocument;
|
const doc = dom.ownerDocument(n);
|
||||||
if (!doc) return false;
|
if (!doc) return false;
|
||||||
const shadowHost = getRootShadowHost(n);
|
const shadowHost = getRootShadowHost(n);
|
||||||
return dom.contains(doc, shadowHost);
|
return dom.contains(doc, shadowHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function inDom(n: Node): boolean {
|
export function inDom(n: Node): boolean {
|
||||||
const doc = n.ownerDocument;
|
const doc = dom.ownerDocument(n);
|
||||||
if (!doc) return false;
|
if (!doc) return false;
|
||||||
return dom.contains(doc, n) || shadowHostInDom(n);
|
return dom.contains(doc, n) || shadowHostInDom(n);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,13 @@ type BasePrototypeCache = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const testableAccessors = {
|
const testableAccessors = {
|
||||||
Node: ['childNodes', 'parentNode', 'parentElement', 'textContent'] as const,
|
Node: [
|
||||||
|
'childNodes',
|
||||||
|
'parentNode',
|
||||||
|
'parentElement',
|
||||||
|
'textContent',
|
||||||
|
'ownerDocument',
|
||||||
|
] as const,
|
||||||
ShadowRoot: ['host', 'styleSheets'] as const,
|
ShadowRoot: ['host', 'styleSheets'] as const,
|
||||||
Element: ['shadowRoot', 'querySelector', 'querySelectorAll'] as const,
|
Element: ['shadowRoot', 'querySelector', 'querySelectorAll'] as const,
|
||||||
MutationObserver: [] as const,
|
MutationObserver: [] as const,
|
||||||
@@ -169,6 +175,10 @@ export function getUntaintedMethod<
|
|||||||
return untaintedMethod.bind(instance) as BasePrototypeCache[K][T];
|
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<Node> {
|
export function childNodes(n: Node): NodeListOf<Node> {
|
||||||
return getUntaintedAccessor('Node', n, 'childNodes');
|
return getUntaintedAccessor('Node', n, 'childNodes');
|
||||||
}
|
}
|
||||||
@@ -266,6 +276,7 @@ export function patch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
ownerDocument,
|
||||||
childNodes,
|
childNodes,
|
||||||
parentNode,
|
parentNode,
|
||||||
parentElement,
|
parentElement,
|
||||||
|
|||||||
Reference in New Issue
Block a user