-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Add support for 'pierce/' selector in Page and ElementHandle. #166
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
base: main
Are you sure you want to change the base?
Conversation
97facbc
to
f35dea4
Compare
|
One of the big mistakes in puppeteer in my opinion is the selector system. I would strongly prefer
In terms of API. In this case though, is there a reason pierce even needs to be a selector type? What I would do is assume the user meant to pierce by default, and have a
I personally don't want to do this, it forces the end user into including types that they might not necessarily want – would rather have unknown or any with a comment explaining why it's necessary. Edit: Seems like we really can't use the triple slash directive – it prevents publishing |
Thanks for the response!
No attachments to the selector syntax, just used due to being prior art, and specifically the simplicity of the interface SelectorOptions {
pierce?: boolean;
}
// Extend WaitForSelectorOptions
interface WaitForSelectorOptions = SelectorOptions & {
timeout?: number
} A note, the puppeteer-style This specific implementation of "piercing" may not directly translate to a Given the current interface SelectorOptions {
pierce?: boolean;
}
class ElementHandle {
$(selector: string, opts:SelectorOptions = { pierce: false }) {
if (opts.pierce) contentPiercingQuerySelector(..)
else CDTQuerySelector(..)
});
}
Spotted that in CI, good catch -- |
Ah okay, I missed that. If that's the case, then let's just do
Not aware of any intermittent test failures, what does it look like? |
For future strategies, I think of type SelectorStrategy = "native" | "pierce"; // Could be "xpath" in the future
interface SelectorOptions {
strategy: SelectorStrategy;
}
// Same with $, $$, waitForSelector, etc.
function $(selector: string, opts: SelectorOptions = { strategy: "native" }): Promise<ElementHandle | null>
All on linux, some failed tests (that sometimes work), I'll look more into it:
It may take a few days for me to get back to this, but interested in following through here, thanks for the feedback! |
Looks good to me, that would be excellent
Haven't seen that before – thanks for noting.
Thank you for the contribution! This is great work. |
937343e
to
ddf8165
Compare
… supporting an optional shadow root piercing strategy.
ddf8165
to
0a76c32
Compare
Getting back to this, just updated the formatting |
The linux CI failures are similar to what I see locally on this branch (and main): intermittent timeouts in tests that use If it's of interest, I could add a simple web server to run alongside the tests (either here, or in a new PR), rough idea:
|
If the test server would fix test timeouts – that would be great. Makes a ton of sense. I would slightly prefer if that was in a seperate PR to make it easier to review. Really good idea! |
Excellent, this went pretty smooth: #167 |
This implements the pierce/ selector to select elements within shadow roots for all relevant APIs (
waitForSelector
,$
,$$
, etc. forPage
andElementHandle
).Some implementation notes:
query.ts
usesElement
type for functions executed in content, and would then introduce the first type directive in non-test source (lib=dom): Any issues with doing so?pierce/
was chosen due to its simplicity as a piercing selector, though there are other forms that have been used in past tools and browsers (>>>
,>>>>
,/deep/
, etc.).Happy to address any feedback needed if this is of interest upstream. Thank you for the project!