[Feature] page.$ and page.$$ should pierce shadow DOM
See original GitHub issueIt seems like page.$
and page.$$
and their eval counterparts do not pierce the shadow DOM?
Should they maybe? It would not be equal to document.querySelector
(or document.querySelectorAll
) anymore then, but I’d say it is worth it?
E.g. when using page.$$
which is the only option when e.g. getting multiple
We also have another case in tests where we in an afterEach()
try to close any open dialogs, just to make sure we have independence between test cases if one fails in the middle of an open dialog. In this case, in the afterEach()
we do:
// a-cool-button is in an open shadow DOM
const dialog = await page.$('a-cool-dialog[show]');
if (dialog) {
await page.click(
'a-cool-dialog[show] a-cool-button'
);
}
We would rather do:
// a-cool-button is in an open shadow DOM
const cancelButton= await page.$('a-cool-dialog[show] a-cool-button');
if (cancelButton) {
await cancelButton.click();
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Shadow DOM v1 - Self-Contained Web Components
Shadow DOM composes different DOM trees together using the <slot> element. Slots are placeholders inside your component that users can fill with ...
Read more >Using shadow DOM - Web Components | MDN
Shadow DOM allows hidden DOM trees to be attached to elements in the regular DOM tree — this shadow DOM tree starts with...
Read more >Encapsulating Style and Structure with Shadow DOM
Currently, the only reliable way to style a shadow DOM node is by adding a <style> element to the shadow root's inner HTML....
Read more >Styling: Styles Piercing Shadow DOM - Open Web Components
What this means is that inheritable styles, like color or font-family among others, continue to inherit in shadow DOM, will pierce the shadow...
Read more >Is a Closed Shadow DOM within Content Script Secure?
Secure against what? What's your threat model? Extensions can definitely pierce the shadow dom. The untrusted page probably not, but the API ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Nevermind, it does pierece the shadow DOM. (I’ll be honest here… it was second hand info that it did not work, I should have tested this myself, apologies).
However, the actual description for all these is not correct anymore. https://github.com/microsoft/playwright/blob/master/docs/api.md#pageselector etc. says:
That cannot be true anymore since the functions pierce the shadow DOM, so it is not a direct mapping to that function which follows the CSS spec.
I assume then that the only difference between e.g.
page.waitForSelector()
andpage.$()
is that the latter do not have any wait at all? Ispage.$
even needed anymore?(personally I feel all the
.$
functions are ambiguous due to no naming and should be deprecated in favor of better named functions where applicable).Hmm… Works for me with playwright v1.0.1:
What am I missing? Did you forget to await? Maybe the site is different?