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

Serializing DOM as rendered, including Shadow DOM #58

Open
michaelcpuckett opened this issue Jan 6, 2020 · 4 comments
Open

Serializing DOM as rendered, including Shadow DOM #58

michaelcpuckett opened this issue Jan 6, 2020 · 4 comments

Comments

@michaelcpuckett
Copy link

michaelcpuckett commented Jan 6, 2020

As a web developer, there are times when I may want to get a string representation of the DOM as rendered. For example, I want to copy and paste the rendered DOM into a service that checks for SEO, Microdata, HTML markup validation, accessibility, etc.

With shadow DOM, doing this manually would very difficult, because there is no "rendered" version available -- in JavaScript you would have to manually replace the slot elements.

I think it would be helpful if we had a way to do this natively, either as part of XMLSerializer, or as a DOM property: .renderedInnerHTML or similar.

@rniwa
Copy link

rniwa commented Jan 14, 2020

Hm... I think we need something like getFlatTree(...shadowRoots) so that only scripts that have access to each ShadowRoot can do such a serialization. Otherwise, we would be violating the encapsulation.

@annevk @smaug----

@annevk
Copy link
Member

annevk commented Jan 14, 2020

How would it serialize though? And how is that useful if it cannot be parsed?

@AKRFranko
Copy link

I'll add another probable use case:

Lets say I use web components as utilities for laying out data, and then I want to send "what it looks like" via an email. How I used to do this pre-shadow-dom days was I'd inline the styles and then just copy the innerHTML to the email. Now, how would I go about doing that without a way of serializing the dom as rendered?

@michaelcpuckett
Copy link
Author

I just read about a new feature -- the declarative Shadow DOM

https://web.dev/declarative-shadow-dom/

element.getInnerHTML({includeShadowRoots: true});

I think that covers this use case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants