From 2c463660b8b35847d26d703680c6a409a3672667 Mon Sep 17 00:00:00 2001 From: edave64 Date: Thu, 18 Jul 2024 14:33:31 +0200 Subject: [PATCH 1/2] Correctly detect elements coming from different realms This does not support elements coming from a third realm, different from the one we are running and the one the document belongs to, but this is even less common than having to deal with crossrealm elements to begin with. (And impossible on Firefox) --- src/registry.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/registry.ts b/src/registry.ts index 45cc4ec..6092a30 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -83,7 +83,11 @@ export default class Registry implements RegistryInterface { } else if (query & Scope.LEVEL & Scope.INLINE) { match = this.types.inline; } - } else if (query instanceof Element) { + } else if ( + query instanceof HTMLElement || + query instanceof + (query.ownerDocument?.defaultView?.HTMLElement ?? HTMLElement) + ) { const names = (query.getAttribute('class') || '').split(/\s+/); names.some((name) => { match = this.classes[name]; From e4bb670114d10347a856608e6e71f1b93548b163 Mon Sep 17 00:00:00 2001 From: edave64 Date: Thu, 18 Jul 2024 14:36:34 +0200 Subject: [PATCH 2/2] Handle contained by checks in documents other than the primary document --- src/blot/abstract/parent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blot/abstract/parent.ts b/src/blot/abstract/parent.ts index 2b1c5fd..c8ea687 100644 --- a/src/blot/abstract/parent.ts +++ b/src/blot/abstract/parent.ts @@ -351,7 +351,7 @@ class ParentBlot extends ShadowBlot implements Parent { node.parentNode != null && // @ts-expect-error Fix me later node.tagName !== 'IFRAME' && - document.body.compareDocumentPosition(node) & + (node.ownerDocument ?? document).body.compareDocumentPosition(node) & Node.DOCUMENT_POSITION_CONTAINED_BY ) { return;