Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shadow DOM innerHTML #8192

Closed
GioValentin opened this issue Aug 13, 2022 · 8 comments
Closed

Shadow DOM innerHTML #8192

GioValentin opened this issue Aug 13, 2022 · 8 comments
Labels
addition/proposal New features or enhancements topic: shadow Relates to shadow trees (as defined in DOM)

Comments

@GioValentin
Copy link

GioValentin commented Aug 13, 2022

REF: w3c/DOM-Parsing#73

There needs to be a way to read the contents of a shadow DOM regardless if it's closed or open when we're not the creator. The function getInnerHTML({includeShadowRoots: true}) works if the shadow root use the template syntax but if a shadow root is generated using a generic implementation like my example below then you can't get the contents of the html of the shadow root.

An example,

var _div = document.createElement('div');
var root = _div.attachShadow({mode: 'open'}); // or closed
var helloWorld = document.createElement('div');
helloWorld.innerHTML = '

Hello World

';
root.appendChild(helloWorld);

I would like to be able to call the element and generate a string by doing element.shadowRoot.innerHTML. This works when we are the creator but it does not work when we're not.

@dylanb
Copy link

dylanb commented Aug 15, 2022

How would you even know that you had to call that function on a closed shadow root element?

@GioValentin
Copy link
Author

Using a mutate observer on the document. @dylanb

@o0101
Copy link

o0101 commented Aug 22, 2022

@GioValentin

Well you can do it with the backend 😄 : DOMSnapshot.captureSnapshot

But I suppose you want a regular web API and not something in the remote debugging protocol 😄

@annevk
Copy link
Member

annevk commented Aug 29, 2022

I'm not sure I understand, getInnerHTML() should always work, regardless of how it was created.

And yeah, I don't see how this would work for closed trees if they are hidden from you.

@annevk annevk added addition/proposal New features or enhancements topic: shadow Relates to shadow trees (as defined in DOM) labels Aug 29, 2022
@dylanb
Copy link

dylanb commented Nov 18, 2022

I think it would be a good idea to have a DOM function that returns a list of all the elements that have shadow trees (open or closed). This would be useful in multiple contexts, including allowing tools that inspect/audit HTML (like axe-core) to be able to flag things it cannot inspect/audit accurately.

@annevk
Copy link
Member

annevk commented Nov 18, 2022

I'm not sure I understand. That would directly go against encapsulation.

I'm inclined to close this issue as nobody clarified things after my prior comment.

@bathos
Copy link

bathos commented Nov 18, 2022

returns a list of all the elements that have shadow trees (open or closed)

Tooling that exposes information about closed shadow trees needs to stay in the tooling layer, not the runtime.

@annevk annevk closed this as completed Nov 18, 2022
@lucgagan
Copy link

How do I convert the output of captureSnapshot to HTML?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements topic: shadow Relates to shadow trees (as defined in DOM)
Development

No branches or pull requests

6 participants