b-fuze / deno-dom

Browser DOM & HTML parser in Deno
https://jsr.io/@b-fuze/deno-dom
MIT License
423 stars 47 forks source link

can't parse shadowroot element #149

Open litttley opened 1 year ago

litttley commented 1 year ago

for example the github commit relative-time element is a shdowroot ,document.querySelector("#repo-content-pjax-container > div > div > div.Layout.Layout--flowRow-until-md.Layout--sidebarPosition-end.Layout--sidebarPosition-flowRow-end > div.Layout-main > div.Box.mb-3 > div.js-details-container.Details > div.Details-content--hidden-not-important.js-navigation-container.js-active-navigation-container.d-md-block > div.Box-row.Box-row--focus-gray.py-2.d-flex.position-relative.js-navigation-item.navigation-focus > div.color-fg-muted.text-right > relative-time").shadowRoot.textContent the selector can't find out

b-fuze commented 1 year ago

Yeah, what you describe depends on two things: custom elements and shadowroots. For the shadow roots to exist you must first register the custom element Javascript classes to add the shadowroots. Just parsing the HTML won't yield you shadowroot nodes, you must also run the Javascript on the page in addition parsing the HTML.

Deno DOM is not meant to be a substitute for a browser and by extension will never execute the Javascript on a page. What I do plan on doing, however, is implementing both the custom element API and the shadow root API in Deno DOM. It's just if you parse the HTML from Github for example you won't get any shadow roots created because that's strictly a Javascript feature and can't be expressed in HTML.