You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Proposal: new API to get text content across shadowRoot #1395
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)
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:
<divid="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.
Activity
annevk commentedon Jul 28, 2025
How would this be different from the
textContentgetter?woody-li commentedon Jul 29, 2025
@annevk You can not use
testContentto get real text content across shadowRoot.annevk commentedon Jul 29, 2025
You'll have to elaborate as this proposal is very much unclear to me.
rniwa commentedon Jul 29, 2025
Perhaps you mean a new API like
Node.prototype.getTextContentwhich takes an optional argument of shadow roots likegetHTML?woody-li commentedon Jul 29, 2025
@rniwa Yeah, it is.
This proposal is meant to resolve how to get text content across shadowRoot.
Both
innerTextandtextContentcannot get text across shadow DOM.For example:
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
innerTextortextContent.This is my first proposal here.
Please let me know if there's any problem.
Thanks.
zcorpan commentedon Aug 25, 2025
Can you elaborate on the use cases, please? It's difficult to evaluate an API proposal without understanding what problem is being solved.