Skip to content

Selection's extend() doesn't work with shadow boundaries #47118

Closed

Description

@webbedspace

Describe the bug:
https://w3c.github.io/selection-api/#dom-selection-extend
According to this spec ↑ Chrome does this correctly and Firefox doesn't do step 5: "If node's root is not the same as the this's range's root, set the start newRange's start and end to newFocus."

To Reproduce:

<!DOCTYPE html>
<body bgcolor="white">
<span id="X">Light DOM</span> <span id="Y">Light DOM</span> 
<span id="Z"><template shadowrootmode=open><mark>Shadow</mark> Root</template></span>
<script>
let s = document.getSelection()
s.setBaseAndExtent(X,0,Y,0)
s.extend(Z.shadowRoot.firstChild,0)
s.extend(Z.shadowRoot.firstChild,1)
</script>

How this seems to work is that s.extend(Z.shadowRoot.firstChild,0) forces the selection to be entirely inside the shadow root (i.e. its start and end both become the start of the mark) and s.extend(Z.shadowRoot.firstChild,1) extends this to cover the end of the mark.

Chrome
Image
Firefox (not to spec)
Image
Servo
Image

Platform:
Windows 10

Activity

  1. added
    C-untriaged
    on Aug 10, 2026
  2. added
    A-content/dom
    C-has-manual-testcase
    and removed
    C-untriaged
    on Aug 11, 2026
  3. added a commit that references this issue on Sep 7, 2026
    7459ed3
  4. added a commit that references this issue on Oct 6, 2026
    39d8edf
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

    A-content/domC-has-manual-testcase

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions