Proposal: new API to get text content across shadowRoot
What problem are you trying to solve?
Currently, we already have HTML-related API: getHTML, setHTML, etc. But there's no way to get text content across shadowRoot.
In some cases, we need to get real text content across element shadowRoots. Such as a customized tooltip, check content in the auto-test frame, etc.
What solutions exist today?
No response
How would you solve it?
How about adding a new API, like getText or getTextContent?
Add an option like checkVisibility to deal with hidden elements. (The difference between innerText and textContent)
Anything else?
No response
How would this be different from the textContent getter?
@annevk You can not use testContent to get real text content across shadowRoot.
You'll have to elaborate as this proposal is very much unclear to me.
Perhaps you mean a new API like Node.prototype.getTextContent which takes an optional argument of shadow roots like getHTML?
@rniwa Yeah, it is.
This proposal is meant to resolve how to get text content across shadowRoot.
Both innerText and textContent cannot get text across shadow DOM.
For example:
<div id="box">
// some other elements.
<my-element>
#shadow-fragment
<span>Some test content</span>
</my-element>
</div>
In some cases, I want to get the real text content of the box element. I have to query every element, check whether it's a custom element, and collect its inner elements again and again. Then, use all elements to map a list of text content.
This proposal is meant to create a new API like getTextContent, using it to get the real text content.
And I think it should contain an options object argument.
One option for deciding whether to get text across shadowRoot.
One option is to get innerText or textContent.
This is my first proposal here. Please let me know if there's any problem. Thanks.
Such as a customized tooltip, check content in the auto-test frame, etc.
Can you elaborate on the use cases, please? It's difficult to evaluate an API proposal without understanding what problem is being solved.