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

A proposal to help with testing/SEO/accessibility of closed ShadowDOM #505

Closed
BronislavKlucka opened this issue May 23, 2016 · 11 comments
Closed

Comments

@BronislavKlucka
Copy link

Hi as mentioned above, this is to help with those issues, not to solve them all, but how about adding

DocumentFragment Element.prototype.cloneShadowDOM()

I hope the signature is self-explanatory and the usecases are quite clear, since we've been discussing those issues for a quite some time.

This would allow closed ShadowDOM to remain closed, but allow crawling copy by script

Brona

@rniwa
Copy link
Collaborator

rniwa commented May 24, 2016

I'd prefer making cloneNode take a dictionary and make add this as an option instead if we can make the first argument polymorphic between boolean and a dictionary:
e.g. element.cloneNode({shadow: true}), element.cloneNode({deep: true, shadow:true}).

@annevk
Copy link
Collaborator

annevk commented May 24, 2016

I don't understand "allow crawling copy by script". Are you suggesting that returns a deep copy of the shadow root that is now accessible and no longer a shadow root but a DocumentFragment node? Why would that be good?

@rniwa that makes more sense to me...

@hayatoito
Copy link
Contributor

Yeah, I think the proposal does not solve an issue at all... :(
You will get yet another instance of "something which is closed". Both instances should stay closed.

@treshugart
Copy link

Is it possible to return a readonly tree from shadowRoot if it's closed instead of returning null?

@annevk
Copy link
Collaborator

annevk commented May 25, 2016

@treshugart I don't know what that means. What is a readonly tree?

@treshugart
Copy link

Immutable representation of the current state of the shadow root.

@annevk
Copy link
Collaborator

annevk commented May 25, 2016

  1. That's not possible without inventing all sorts of new data structures.
  2. That goes against what "closed" means.

@BronislavKlucka
Copy link
Author

BronislavKlucka commented May 25, 2016

Appearently it was not as obvious as I assumed
The intent is not to clone shadowRoot, but the content of the shadowRoot

<x-user>
  #shadowRoot
     <h1>Brona</h2>
     <span>Czech Republic</span> 
</x-user>

var docFrag = document.querySelector("x-user").cloneShadowDOM()

docFrag:

#DocumentFragment
  <h1>Brona</h2>
  <span>Czech Republic</span> 

the copy is of the content of the shadowRoot, not the shadowRoot itself. No open, closed mode applies. It is regular DocumentFragment This allows for content to be crawled for testing/SEO/accessibility purposes while leaving the original closed shadowRoot intact

@annevk
Copy link
Collaborator

annevk commented May 25, 2016

That is what I assumed you meant in #505 (comment). As far as I can tell that still leaks the kind of thing "closed" does not want to leak.

@BronislavKlucka
Copy link
Author

BronislavKlucka commented May 25, 2016

I assumed, the reason for closed is "not to be tempered with", not necessary "not to be read"

@andyearnshaw
Copy link

Reading it means that your program could become dependant on the internal state of the tree, which defeats one of the advantages closed provides.

For automated testing, consideration for shadow trees really needs adding to the WebDriver spec. This has to be done regardless of any new methods that could be added to web components, so there's little point in adding them purely for that purpose.

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

6 participants