coderef

Selection composed rangesBaseline · Newly available

The window.getSelection().getComposedRanges() method returns ranges that represent the current user selection, even if the selection spans across shadow tree boundaries.

Works in the latest version of every major browser, but older devices may not support it yet. Baseline since Aug 19, 2025.

Browser support

DesktopChrome
1–136Not supported
137+Supportedsince May 27, 2025
Current: 155
Edge
12–136Not supported
137+Supportedsince May 29, 2025
Current: 154
Firefox
1–141Not supported
142+Supportedsince Aug 19, 2025
Current: 157
Safari
1–16.6Not supported
17+Supportedsince Sep 18, 2023
Current: 27
MobileChrome Android
18–136Not supported
137+Supportedsince May 27, 2025
Current: 155
Firefox Android
4–141Not supported
142+Supportedsince Aug 19, 2025
Current: 157
Safari iOS
1–16.6Not supported
17+Supportedsince Sep 18, 2023
Current: 27

How to use

Every current browser supports this, but it only became Baseline on Aug 19, 2025. Use it as a progressive enhancement, or keep a fallback if you support older devices.

Example

Full syntax and examples are on MDN: getComposedRanges.

Feature detection

JS · check before using
if ("Selection" in globalThis && "getComposedRanges" in Selection.prototype) {
  // Selection.getComposedRanges is available
}