From a752f019d2472b52100e1cbe71a469d9526e3607 Mon Sep 17 00:00:00 2001 From: honlyHuang <3080820+honlyHuang@users.noreply.github.com> Date: Mon, 22 Dec 2025 17:59:49 +0800 Subject: [PATCH] fix: child return false in iframe srcdoc child instanceof HTMLElement has some common pitfalls: google output this: 1. Multiple Realms (iframes): If you check an element created inside an iframe against the HTMLElement constructor of the main window, it will return false. This is because each window/iframe has its own global environment and constructor. 2. SVG Elements: An SVG element is an instance of SVGElement, not HTMLElement. To check for any visible DOM element (including SVG or MathML), you should use child instanceof Element instead. 3. Alternative Property: If you only need to distinguish between nodes and elements without using instanceof, you can check if child.nodeType === 1. --- src/embed-webfonts.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/embed-webfonts.ts b/src/embed-webfonts.ts index a84a699d..1883d9f7 100644 --- a/src/embed-webfonts.ts +++ b/src/embed-webfonts.ts @@ -216,8 +216,9 @@ function getUsedFonts(node: HTMLElement) { }) Array.from(node.children).forEach((child) => { - if (child instanceof HTMLElement) { - traverse(child) + if (Object.prototype.toString.call(child).includes('HTML') && + child.nodeType === 1) { + traverse(child as HTMLElement) } }) }