Skip to content

Proposal: new API to get text content across shadowRoot #1395

Open

Description

@woody-li

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

Activity

  1. annevk commented on Jul 28, 2025

    @annevk
    Member

    How would this be different from the textContent getter?

  2. woody-li commented on Jul 29, 2025

    @woody-li
    Author

    @annevk You can not use testContent to get real text content across shadowRoot.

  3. annevk commented on Jul 29, 2025

    @annevk
    Member

    You'll have to elaborate as this proposal is very much unclear to me.

  4. rniwa commented on Jul 29, 2025

    @rniwa

    Perhaps you mean a new API like Node.prototype.getTextContent which takes an optional argument of shadow roots like getHTML?

  5. woody-li commented on Jul 29, 2025

    @woody-li
    Author

    @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.

  6. zcorpan commented on Aug 25, 2025

    @zcorpan
    Member

    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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    addition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interesttopic: nodestopic: shadowRelates to shadow trees (as defined in DOM)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions