A general-purpose DOM tree walker based on https://stackoverflow.com/questions/10730309/find-all-text-nodes-in-html-page (Phrogz' answer and its comments).
The textNodesUnder() function would then look like this:
function textNodesUnder(el) {
return walkNodeTree(el, {
inspect: n => !['STYLE', 'SCRIPT'].includes(n.nodeName),
collect: n => (n.nodeType === Node.TEXT_NODE),
//callback: n => console.log(n.nodeName, n),
});
}
You're right. I got conflated for a couple of reasons:
NodeFilter.SHOW_TEXTwas used instead ofNodeFilter.SHOW_ALLfor the 2nd argument when creating theTreeWalker(to make a manualnodeTypecheck unnecessary), then the issue would occur.