Re: [GoogleChrome/puppeteer] Query nodes within shadow roots (#858)

@elf-pavlik Our solution has been crafted to work well in our specific scenario. I don't think it would work well for puppeteer because it selects items based on the flattened tree and requires a cache of the flattened tree to work. This would probably perform very badly in puppeteer because unlike axe-core, you cannot assume that the DOM will not change between selectors (in fact it most likely will change), so you would constantly have to update the cache - which you don't need anyway.

I could certainly use my  knowledge of the problem domain to help.

One thing we will have to do is define a "selector syntax" for piercing shadow DOM.

One option for a selector syntax would be to override the DOM piercing combinator `'>>>'`. Alternatives include `'>>'` or `'<<<'`

I would define the behavior such that the right hand selector component applies to the shadow root of the results of the left hand selector component. 

A selector of `'my-component:nth-of-type(2) >>> #thing-i-want-to-target'` would, for example, find (all the) element(s) with the id of `thing-i-want-to-target` within the specific instance of a custom element `<my-component>`.

This is different from @aslushnikov example in that it would not pierce with a simple selector `'div'` but would pierce with the selector `'* >>> div'` and would only pierce one level. To pierce multiple levels, you would have to specify the number of levels you want. E.g. `'* >>> * >>> .thing'`.

The advantage of this is you can very specifically target elements. The downside is you have to know how many levels down your target is.

We could also possibly implement two different selectors, one that behaves as described above and one that allows you to select a specific shadow host and then pierce down all its levels. Perhaps `'>>'` and `'>>>'` respectively.

thoughts?

-- 
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
https://github.com/GoogleChrome/puppeteer/issues/858#issuecomment-362936400

Received on Sunday, 4 February 2018 20:23:21 UTC