Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Support custom elements with Shadow DOM #51

Closed
elf-pavlik opened this issue Apr 25, 2019 · 11 comments
Closed

Support custom elements with Shadow DOM #51

elf-pavlik opened this issue Apr 25, 2019 · 11 comments
Labels
👌 accepted Feature accepted 🆘 help wanted Extra attention is needed
Projects

Comments

@elf-pavlik
Copy link

related issue: puppeteer/puppeteer#4171

When I record interaction with this plugin, it doesn't seem to see anything in shadow dom of custom elements and just records events on parent in the top level dom.

@mrtnmgs
Copy link

mrtnmgs commented Jun 5, 2019

I have the same issue. Things are working fine with a native input, but when I type in a web component it creates a page.type call but the text is undefined.
Definitely shadow DOM related: things work as expected if I turn shadow DOM off in the same component.

...
await page.type('body > div > input', 'Hello')
await page.type('body #my-component', 'undefined')
...

@tnolet
Copy link
Member

tnolet commented Jul 4, 2019

@elf-pavlik @mrtnmgs thanks for reporting. It would really help if I have a reproducable tests case. Either a small project or live web page to test this out on.

@elf-pavlik
Copy link
Author

for example https://demo.vaadin.com/invoice-editor-app/ has each input inside different shadow dom

@bennypowers
Copy link

If we have a JavaScript context here https://github.com/checkly/puppeteer-recorder/blob/920f786695a844ff07e04cadf2f017b79215faca/src/content-scripts/EventRecorder.js#L96 then we could get the composedPath() of the event. At that point, we can recurse over the path, and anywhere we find a shadow root, we can interpolate some magic string like /PUPPETEER_RECORDER_DEEP/ into the selector.

Later, in the puppeteer script, when we find a selectors that include that string, we can split it and drill down into the shadow root

@tnolet
Copy link
Member

tnolet commented Jul 16, 2019

@bennypowers this sounds like an interesting direction. The most important thing would be it doesn't break current behaviour, as shadow DOM is probably not as widely used as "plain old DOM"

@bennypowers
Copy link

bennypowers commented Jul 16, 2019

The most important thing would be it doesn't break current behaviour

Seems legit to rely on our own magic string in the selector. For extra security, you could recursively walk up the DOM through the composedPath() and check for the existence of shadowRoots first

while (host = host.getRootNode().host) this.#shadowHosts.push(host);
// pseudocode
if (!this.#shadowHosts.length) normalSelector()
else shadowSelector()

then while replaying

// pseudocode
if (selector.includes(MAGIC_SHADOW_DOM_STRING)) sneakThroughTheShadows(selector)
else processNormally(selector)

@elf-pavlik
Copy link
Author

elf-pavlik commented Jul 16, 2019

Maybe recording could provide jsPath as suggested in puppeteer/puppeteer#858 (comment) and later in puppeteer/puppeteer#4171

@ianaya89 ianaya89 changed the title support custom elements with shadow dom Support custom elements with shadow DOM Jan 19, 2021
@ianaya89 ianaya89 changed the title Support custom elements with shadow DOM Support custom elements with Shadow DOM Jan 19, 2021
@ianaya89 ianaya89 added the 🆘 help wanted Extra attention is needed label Jan 19, 2021
@sghsri
Copy link

sghsri commented Jul 11, 2021

Any update on this?

@ianaya89
Copy link
Contributor

@sghsri no yet.
We recently released a new version of HR (new design, bug fixes and UX improvements).
I will start researching on this and find possible workarounds

@ianaya89 ianaya89 added the 👌 accepted Feature accepted label Aug 29, 2021
@ianaya89 ianaya89 added this to Backlog in Maintenance Aug 29, 2021
@conceptree
Copy link

Hello, in a project that I am part of, we write our UI apps in stencil JS web components. We seek for quiet a while for a solution that records user interactions for automation purposes. It will be great if you solve this.

@ianaya89
Copy link
Contributor

#232

@ianaya89 ianaya89 moved this from Backlog to Done in Maintenance Dec 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
👌 accepted Feature accepted 🆘 help wanted Extra attention is needed
Projects
No open projects
Maintenance
  
Done
Development

No branches or pull requests

7 participants