puppeteer-core
Version:
A high-level API to control headless Chrome over the DevTools Protocol
38 lines • 1.16 kB
JavaScript
/**
* @license
* Copyright 2022 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import { createTextContent, isSuitableNodeForTextMatching, } from './TextContent.js';
/**
* Queries the given node for all nodes matching the given text selector.
*
* @internal
*/
export const textQuerySelectorAll = function* (root, selector) {
let yielded = false;
for (const node of root.childNodes) {
if (node instanceof Element && isSuitableNodeForTextMatching(node)) {
for (const match of textQuerySelectorAll(node, selector)) {
yield match;
yielded = true;
}
}
}
if (root instanceof Element && root.shadowRoot) {
for (const match of textQuerySelectorAll(root.shadowRoot, selector)) {
yield match;
yielded = true;
}
}
if (yielded) {
return;
}
if (root instanceof Element && isSuitableNodeForTextMatching(root)) {
const textContent = createTextContent(root);
if (textContent.full.includes(selector)) {
yield root;
}
}
};
//# sourceMappingURL=TextQuerySelector.js.map