-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better Support for Shadow DOM #4171
Comments
Another thing to consider that in an application where every (web)component is a shadow root, this would basically be equivalent to an exact step by step DOM path instead of a "selector". This means you would have to update all your e2e tests every time you change anything about the DOM structure, which would be extremely annoying (no matter if it supports JS path or arrays). Maybe another better option would be to have an option |
Could the |
Btw, how do XPath queries behave with regards to shadow roots? |
Also with the new introduction of |
await page.click(() => window.mySuperCoolElement) |
Maybe |
I feel like most of solutions to shadow Dom in puppeteer force the tests/tester to have to know far too much about the structure of the application. Having page.click work with jsPath would make a library I wrote a bit easier to work with. (Below) The purpose of the library is to allow you to just write a normal querySelector and it will automatically find the selector whether it's in a shadow root or deeply nested shadow roots. For now I use evaluateHandle and return the ElementHandle which you can do clicks, types, select etc on. I've thought about wrapping the above snippet into a library that lets you pass in a puppeteer page object and a querySelector. |
Having experimented with this, and added my custom Having to specify the exact DOM tree with an array, or with other means such as what JSPath requires, is not ideal. Imagine you move around a generic component called Moreover, if you want to test it on various viewport sizes, the actual DOM can look different which means tests will not work anyway. @aslushnikov Considering Web Components is becoming more used, is there a plan to natively implement penetrating shadow DOMs into Pupeteer, or is it a low priority task? |
@aslushnikov Is there any planned worked for this from the Puppeteer team? Considering about %8 of page loads use custom elements (and most likely shadow dom) it feels like a prominent framework such as Puppeteer could use a more native approach :) |
If there is anyone out there who was trying to do SSR with web components I finally figured out how to support this in puppeteer. You need to use Declarative Shadow DOM. In your
Then add a
Then to serialize you need:
The |
Since #6509 and 5.4.0 there is now a pierce handler. it('should find all elements in shadow', async () => {
const { page } = getTestState();
const divs = await page.$$('pierce/.foo');
const text = await Promise.all(
divs.map((div) =>
div.evaluate((element: Element) => element.textContent)
)
);
expect(text.join(' ')).toBe('Hello World');
}); Or you can have a look at the test example in the original PR. |
This is necessary to use declarative shadow DOM in a headless Chrome browser. See [puppeteer/puppeteer#4171 (comment)](puppeteer/puppeteer#4171 (comment)).
This is necessary to use declarative shadow DOM in a headless Chrome browser. See [puppeteer/puppeteer#4171 (comment)](puppeteer/puppeteer#4171 (comment)).
This is necessary to use declarative shadow DOM in a headless Chrome browser. See [puppeteer/puppeteer#4171 (comment)](puppeteer/puppeteer#4171 (comment)).
Since
Copy JS Path
has landed in Chrome DevTools, we now have a way to address nodes inside shadow DOM.Details: #858 (comment)
This, however, doesn't simplify life much when it comes to sugar methods, such as
page.click
,page.select
and others.It'd be nice to have a way to address nodes in shadow DOM in these methods.
Suggestions:
page.click
and others to accept an array of selectors. (source).page.click
and others to treat jsPaths as selectors.cc @JoelEinbinder
The text was updated successfully, but these errors were encountered: