Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Intent to Ship: Selection API getComposedRanges and direction

154 views
Skip to first unread message

Di Zhang

unread,
Mar 25, 2025, 7:42:06 PMMar 25
to blink-dev
Contact emails
None

Specification
https://w3c.github.io/selection-api/#dom-selection-getcomposedranges

Summary

This feature ships two new API methods for the Selection API: * Selection.direction which returns the selection's direction as either "none", "forward" or "backward" * Selection.getComposedRanges() which returns a list of 0 or 1 “composed” StaticRange A “composed” StaticRange is allowed to cross shadow boundaries, which normal Ranges cannot. For example: const range = getSelection().getComposedRanges({ shadowRoots: [root] }); If the selection crosses a shadow root boundary that isn’t provided in the shadowRots list, then the StaticRange's endpoints will be “rescoped” to be outside that tree. This makes sure we do not expose unknown shadow trees.



Blink component
None

TAG review status
Issues addressed

Risks


Interoperability and Compatibility

None



Gecko: Positive (https://github.com/mozilla/standards-positions/issues/1055) Currently in development. https://groups.google.com/a/mozilla.org/g/dev-platform/c/zF7soLapT-Y

WebKit: Shipped/Shipping (https://github.com/WebKit/WebKit/pull/10843#issuecomment-1592149737) Partially shipped new API

Web developers: Positive (https://stackoverflow.com/questions/62054839/shadowroot-getselection)

Other signals:

WebView application risks

Does this intent deprecate or change behavior of existing APIs, such that it has potentially high risk for Android WebView-based applications?

No, this is only shipping new APIs without modifying existing behavior.



Debuggability

None



Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, ChromeOS, Android, and Android WebView)?Yes

The Selection API is supported on all platforms.



Is this feature fully tested by web-platform-tests?Yes

Tests can be found at https://wpt.fyi/results/selection/shadow-dom/tentative?label=experimental&label=master&aligned



Flag name on about://flags
SelectionAcrossShadowDOM

Finch feature name
SelectionAcrossShadowDOM

Requires code in //chrome?
False

Tracking bug
Feature is available on Web Platform Baseline within 6 months of launch in Chrome.

Adoption expectation
Feature is available on Web Platform Baseline within 6 months of launch in Chrome.

Adoption plan
The feature is already shipped in Safari/Webkit and Firefox has an implementation in Nightly. They mentioned also wanting to land this within 2025.

Estimated milestones
Shipping on desktop

137

Shipping on Android

137

Shipping on WebView

137


Anticipated spec changes

Open questions about a feature may be a source of future web compat or interop issues. Please list open issues (e.g. links to known github issues in the project for the feature specification) whose resolution may introduce web compat/interop risk (e.g., changing to naming or structure of the API in a non-backward-compatible way).

This new API is important to return Selection endpoints that are inside a shadow DOM and currently not accessible by API. This depends on new specification definitions of what it means to have a range that is composed and how the endpoints should be compared. That specification includes tree traversal, boundary point comparisons and the specification language is quite complex. The specification PR has been open since Dec 17, 2024 and is stalling due to disagreement on how to phrase/word the spec. There are a few remaining open issues about this, but none of those should affect the shape of the API - they only affect the spec text itself.
https://github.com/w3c/selection-api/pull/345

Link to entry on the Chrome Platform Status

Daniel Clark

unread,
Mar 25, 2025, 10:17:59 PMMar 25
to Di Zhang, blink-dev

Looking at the WPT results, there are a lot of Safari failures despite them having already shipped this.

https://wpt.fyi/results/selection/shadow-dom/tentative?label=experimental&label=master&aligned

Do you have an understanding of what those gaps are, and whether there’s a path towards resolving them and ending up with interoperable implementations?

 

I am also wondering if there should be a TAG review for this. It seems that the spec is still somewhat in flux and the shipped WebKit implementation doesn’t align all that closely with Chromium’s given the WPT results, so I’m not sure this Intent quite meets the spirit of the exceptions for a TAG review. And in any case the TAG may be able to help unblock some of the disagreements that have caused the spec changes to stall out.

 

-- Dan

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/10d2631e-2014-42ac-9343-c6d43ff47975n%40chromium.org.

Di Zhang

unread,
Mar 26, 2025, 5:38:45 PMMar 26
to blink-dev, dan...@microsoft.com, Di Zhang
The WPT tests failing is mostly because Safari still using the old specification for getComposedRanges() syntax. This change was resolved in September 2024: https://github.com/w3c/selection-api/pull/331

I have opened an issue with MDN to update the site: https://github.com/mdn/content/issues/38810
I have opened an issue in Webkit Bugzilla: https://bugs.webkit.org/show_bug.cgi?id=290480

There are also some implementation details getting defined that these tests are testing. Implementers are in favor of making progress, but it is stalling due to disagreement on how to phrase/word the spec.

It looks like I missed the TAG review field, sorry about that. This feature has already gone through a TAG review:

To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+unsubscribe@chromium.org.

Vladimir Levin

unread,
Apr 1, 2025, 10:23:16 PMApr 1
to blink-dev, Di Zhang, dan...@microsoft.com
LGTM1

Mike Taylor

unread,
Apr 2, 2025, 9:05:30 AMApr 2
to Vladimir Levin, blink-dev, Di Zhang, dan...@microsoft.com

LGTM2

To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/7c042fed-e301-4cf1-9cfc-533a2fbe8b73n%40chromium.org.

Daniel Bratell

unread,
Apr 2, 2025, 9:46:41 AMApr 2
to Mike Taylor, Vladimir Levin, blink-dev, Di Zhang, dan...@microsoft.com
Reply all
Reply to author
Forward
0 new messages