Skip to content

Commit

Permalink
fix: use shadowRoot for tree walker (#9950)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrandolf committed Mar 31, 2023
1 parent 1396274 commit 728547d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/puppeteer-core/src/injected/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export function* pierce(root: Node): IterableIterator<Node | ShadowRoot> {
* @internal
*/
export function* pierceAll(root: Node): IterableIterator<Node | ShadowRoot> {
yield* pierce(root);
root = pierce(root).next().value;
yield root;
const walkers = [document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT)];
for (const walker of walkers) {
let node: Element | null;
Expand Down
18 changes: 18 additions & 0 deletions test/src/queryhandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,24 @@ describe('Query handler tests', function () {
})
).toBeTruthy();
}
{
const elements = await page.$$('#c >>>> div');
assert(elements[0], 'Could not find element');
expect(
await elements[0]?.evaluate(element => {
return element.id === 'd';
})
).toBeTruthy();
}
{
const elements = await page.$$('#c >>> div');
assert(elements[0], 'Could not find element');
expect(
await elements[0]?.evaluate(element => {
return element.id === 'd';
})
).toBeTruthy();
}
});

it('should work with text selectors', async () => {
Expand Down

0 comments on commit 728547d

Please sign in to comment.