Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The MediaDevices method selectAudioOutput() prompts the user to select a specific audio output device, for example a speaker or headset. On success, the returned Promise is resolved with a MediaDeviceInfo describing the selected device.




options Optional

An object that configures what device(s) may be offered in the user prompt.

deviceId Optional

A string representing the id of the (only) device to display in the prompt (with default value: "").

Note: A user agent may choose to skip prompting the user if a specified non-null id was previously exposed to the user by selectAudioOutput() in an earlier session. In this case the user agent may simply resolve with this device id, or a new id for the same device if it has changed.

This is intended for applications that want to use persisted device ids. The ids must be passed through selectAudioOutput() successfully before they will work with setSinkId().

Return value

A Promise that receives a MediaDeviceInfo object when the promise is fulfilled. The object describes the user-selected audio output device.


NotAllowedError DOMException

Returned if the current page has not been granted the speaker-selection permission or the user closed the selection prompt without choosing a device.

NotFoundError DOMException

Returned if there are no available audio output devices.

InvalidStateError DOMException

Returned if there hasn't been a transient activation (you must trigger it from some kind of UI event).


Transient user activation is required. The user has to interact with the page or a UI element in order for this feature to work.

Access to audio output devices is gated by the Permissions API. The prompt will not be displayed if the speaker-selection permission has not been granted.


Here's an example of using selectAudioOutput(), within a function that is triggered by a button click. It outputs the selected device IDs and labels (if available) or an error message.

document.querySelector('#myButton').addEventListener('click', () => {
  if (!navigator.mediaDevices.selectAudioOutput) {
    console.log('selectAudioOutput() not supported.');

  // Display prompt and log selected device or error
    .then((device) => {
      console.log(`${device.kind}: ${device.label} id = ${device.deviceId}`);
    .catch((err) => {
      console.error(`${}: ${err.message}`);

On selection of an output this might produce:

audiooutput: Realtek Digital Output (Realtek(R) Audio) id = 0wE6fURSZ20H0N2NbxqgowQJLWbwo+5ablCVVJwRM3k=


Audio Output Devices API
# dom-mediadevices-selectaudiooutput

Browser compatibility

BCD tables only load in the browser

See also

  • WebRTC - the introductory page to the API