v136 · 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
setPreferredSinkId persists a user's chosen audio output for the origin. Saves the per-session re-selection that setSinkId required.
-
Iframe inherits sink
The motivating use case: a parent frame's preferred-sink choice flows into child iframes' audio elements without postMessage. Pick a sink in the parent — the iframe's
audio.sinkIdupdates live. -
Multi-track Sink Switcher
Two synthesised tones, one frame-default sink, and per-element overrides. Watch the frame default route every audio element — then watch
audio.setSinkId()beat the default for one track. -
Sink permission flow
Walk the full permission pipeline: enumerate devices (IDs hidden without permission) → request
getUserMediaaudio → re-enumerate (IDs now visible) → callsetPreferredSinkId. Explains whydeviceId: ""appears before permission is granted.
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.