webdriverio / query-selector-shadow-dom

querySelector that can pierce Shadow DOM roots without knowing the path through nested shadow roots. Useful for automated testing of Web Components. Production use is not advised, this is for test environments/tools such as Web Driver, Playwright, Puppeteer
MIT License
238 stars 25 forks source link

override document.querySelector? #79

Open TheDevelolper opened 2 years ago

TheDevelolper commented 2 years ago

So I'm trying to make a web component library that uses a shadow DOM.

I wondered if it was possible to override document.querySelector? Perhaps document.querySelector could be cloned to some other function then your code could call the clone. Then document.querySelector could be overridden to call your deep query selectors?

Then the consumer doesn't have to do anything different from what they're used to?

NikhilVerma commented 1 year ago

This library still uses native query selector internally. I've modified and published it as a ponyfill (crediting the original project ofcourse) https://www.npmjs.com/package/query-selector-ponyfill

This just needs to be included in your project and it should work out of the box