<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>265632</bug_id>
          
          <creation_ts>2023-11-30 23:54:17 -0800</creation_ts>
          <short_desc>Selection API introduced in Safari 17.1 does not handle shadow dom</short_desc>
          <delta_ts>2023-12-01 06:01:41 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>Safari 17</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>sghzal</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>mike</cc>
    
    <cc>rniwa</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1996136</commentid>
    <comment_count>0</comment_count>
    <who name="">sghzal</who>
    <bug_when>2023-11-30 23:54:17 -0800</bug_when>
    <thetext>Safari 17.1 introduced a new selection API that was supposed to handle selection within the shadow DOM as per https://bugs.webkit.org/show_bug.cgi?id=163921 

On github: https://github.com/WebKit/WebKit/pull/10843#issuecomment-1806339821


However the new selection api in the shadow DOM is not working as expected in Safari 17.1. The selection object will not contain valid dom elements and offsets.


To reproduce please use the following html/js snippet in Safari 17.1 (https://jsfiddle.net/souf123/Ly1mvxdf/2/):

```html
&lt;div id=&quot;host&quot;&gt;&lt;/div&gt;
&lt;span&gt;I&apos;m not in the shadow DOM&lt;/span&gt;
```

```js
const host = document.querySelector(&quot;#host&quot;);
const shadow = host.attachShadow({ mode: &quot;open&quot; });
const span = document.createElement(&quot;span&quot;);
span.textContent = &quot;I&apos;m in the shadow DOM&quot;;
shadow.appendChild(span);

document.addEventListener(&apos;selectionchange&apos;, () =&gt; {
  console.log(window.getSelection().getComposedRanges()[0]);
} );
```

You can observe that the returned value from &quot;getComposedRanges&quot; does not contain correct information about the actually selected range.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1996196</commentid>
    <comment_count>1</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2023-12-01 06:01:41 -0800</bug_when>
    <thetext>You need to pass in each ShadowRoot as an argument to getComposedRanges as in:
getComposedRanges(shadow) in the example above.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>