Skip to content

isDOM doesn't work on elements outside of current window #644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
yourWaifu opened this issue May 4, 2025 · 1 comment
Open

isDOM doesn't work on elements outside of current window #644

yourWaifu opened this issue May 4, 2025 · 1 comment

Comments

@yourWaifu
Copy link

yourWaifu commented May 4, 2025

This code

export function isDOM(node: any): node is HTMLElement | SVGElement {
// https://developer.mozilla.org/en-US/docs/Web/API/Element
// Since XULElement is also subclass of Element, we only need HTMLElement and SVGElement
return node instanceof HTMLElement || node instanceof SVGElement;
}

Fails when node is not inside the current window. The main use case is using one screen for presentation and another screen for information that the presenter see.

an idea of a fix:

const nodeWindow = node?.ownerDocument?.defaultView;
return node instanceof nodeWindow.HTMLElement || node instanceof nodeWindow.SVGElement;

The issue is that the above code doesn't really work because you need to know if node is an Element first before getting the window, so we'll need a better idea for a fix.

a fix that I feel like is a hack:

return "nodeType" in node && node === Node.ELEMENT_NODE && "tagName" in node;

I don't know if this is good enough, but it works, fixes the bug.

same thing also happens here

if (element instanceof Element) {

@yourWaifu
Copy link
Author

yourWaifu commented May 7, 2025

I found this pull request contains fixes for this #639

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant