question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Native shadow DOM support

See original GitHub issue

Web Components is a growing trend and statistics show it is used more often than major libraries like React. I’ve got no statistics on how often the shadow DOM is used though. In any instance, the shadow DOM is standardized, so I would assume people will expect support out-of-the-box.

The project https://github.com/Georgegriff/query-selector-shadow-dom works perfectly for now.

const { selectorEngine } = require("query-selector-shadow-dom/plugins/playwright");
const playwright = require('playwright');
...
await playwright.selectors.register(selectorEngine, { name: 'shadow' })
...
  await page.goto('chrome://downloads');
  // shadow= allows a css query selector that automatically pierces shadow roots.
  await page.waitForSelector('shadow=#no-downloads span', {timeout: 3000})

https://github.com/mmarkelov/jest-playwright#configuration also supports it nicely.

But seeing as it requires a new selectorEngine, means the nice selector engines like css, xpath and text do not work on the shadow DOM by default.

If Playwright would support adding a penetrateShadowDOM on a browser, browserContext or page, it would be amazing for usability.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

5reactions
Georgegriffcommented, Apr 16, 2020

Just took a little look at the code changes this look fantastic! After years of trying to say to people tests shouldn’t have to care about shadow Dom boundaries and having to manually pierce shadow Dom is lame, so much so I had to write a library around it, I’m so happy that my library will be redundant in playwright 😄 excited to try it out

5reactions
dgozmancommented, Apr 8, 2020

We definitely want to address this usecase, as it is a part of web standards. Our current approach with >> does not work nicely, that’s why I am changing built-in selectors to pierce shadow. We’ll likely introduce some kind of built-in deep css selector, inspired by query-selector-shadow-dom.

cc @Georgegriff

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Shadow DOM (V1) | Can I use... Support tables for ... - CanIUse
Method of establishing and maintaining functional boundaries between DOM trees and how these trees interact with each other within a document, thus enabling ......
Read more >
Shadow DOM Support - Pendo Help Center
Pendo supports Shadow DOM elements for feature tagging and page element positioning for Guides. What is a Shadow DOM? It is a web...
Read more >
Shadow DOM v1 - Self-Contained Web Components
Shadow DOM allows web developers to create compartmentalized DOM and CSS for web components.
Read more >
Shadow DOM Support & reusable component objects
Shadow DOM is one of the key browser features that make up web components. Web components are a really great way to build...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found