← Back to release summary

Selection API getComposedRanges and direction

Category
Miscellaneous
Type
Chromium catches up
Status
In developer trial (Behind a flag) (Chrome 137)
Intent stage
None

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.

Motivation

Shadow DOM is now supported across all major rendering engines. We should update the Selection API so users can select across shadow boundaries and see interoperable behaviors. The new changes include API support for multiple ranges across a composed tree.

Standards & signals

View on chromestatus.com