v133 · webrtc
Audio Output Devices API: setPreferredSinkId()
Adds setPreferredSinkId() to MediaDevices, which enables a top-level frame to override the default audio output device for all audio renderers in the top-level frame and its child frames, including cross-origin child frames. Audio renderers include HTML <media> elements and web audio contexts.
concepts
-
setPreferredSinkId
Persist the chosen audio output device for the origin.
-
Cross-origin iframe
The motivating use case: route audio for a cross-origin iframe from the top frame — no
postMessagehandshake, no per-elementsetSinkIdin the child. -
Device picker with capability probe
Detect
setPreferredSinkId, legacy per-elementsetSinkId, and the unpromptedselectAudioOutputpicker. Enumerate sinks and apply the user's choice through the best available API. -
WebAudio + media element routing
An oscillator, a sample player, and a media element all routed through one document-wide preferred sink. Switch device once, every renderer follows — no per-source rewiring.
why it shipped
Without setPreferredSinkId(), a top-level frame has no mechanism to change the default audio output device in its cross-origin child frames. A top-level frame cannot use setSinkId() in a cross-origin child frame due to security boundaries. Instead, the top-level frame and cross-origin child frame must collaborate using postMessage() to change the audio output device.