Commit 908c8159 authored by Robert Knight's avatar Robert Knight

Fix issue with `getTextNodes` and nodes from other iframes

I don't believe this issue will ever occur in the real application, but
we currently have tests (in `html-test.js`) where the passed node comes from
a different iframe and therefore a different JS environment where globals including
`Text` and `Element` have different identities.
parent 28300faf
......@@ -70,10 +70,12 @@ export function xpathFromNode(node, root) {
export function getTextNodes(element) {
const nodes = [];
for (let node of Array.from(element.childNodes)) {
if (node instanceof Text) {
nodes.push(node);
} else if (node instanceof Element) {
nodes.push(...getTextNodes(node));
// We test `nodeType` here rather than using `instanceof` because we have
// tests where `node` comes from a different iframe.
if (node.nodeType === Node.TEXT_NODE) {
nodes.push(/** @type {Text} */ (node));
} else if (node.nodeType === Node.ELEMENT_NODE) {
nodes.push(...getTextNodes(/** @type {Element} */ (node)));
}
}
return nodes;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment