Code
Browser Web APIs
Allows web applications to redirect audio output to a permitted Bluetooth headset, speakerphone, or other device.
Provides a way for browsers to better manage audio sessions and inform browsers about what kind of audio is being played.
Provides a method for managing downloads that may take a significant amount of time, running in the background if the user navigates away.
Enables web apps to defer tasks to be run in a service worker once the user has a stable network connection.
Allows scheduling of non-critical work to be performed during idle periods via requestIdleCallback.
Allows installed web apps to set a badge on the app icon to notify users of pending activity such as messages or updates.
Detects linear and two-dimensional barcodes, including QR codes, in images and video streams.
Provides information about the battery charge level of the device and notifications when the level or status changes.
Sends asynchronous, non-blocking requests to a server without expecting a response, ideal for analytics and diagnostics.
Enables simple communication between browsing contexts such as tabs, windows, and iframes sharing the same origin.
Audio Output Devices API
ExperimentalAllows web applications to prompt users to select an audio output device (speaker, headset, etc.) and redirect audio playback to it. Requires a secure context (HTTPS) and transient user activation.
Key Interfaces
MediaDevices.selectAudioOutput()— Prompts the user to select an audio output device and returns itsMediaDeviceInfo.HTMLMediaElement.setSinkId(deviceId)— Routes audio output to a device by its ID.HTMLMediaElement.sinkId— Read-only. The current audio output device ID (empty string = browser default).
Example — Select output device and redirect audio
Trigger on a user gesture (e.g. button click). Prompt the user to choose an output device, then redirect a playing audio element to that device.
document.querySelector('#selectOutputBtn').addEventListener('click', async () => {
if (!navigator.mediaDevices.selectAudioOutput) {
console.log('selectAudioOutput() not supported or not in secure context.');
return;
}
// Prompt user to choose an audio output device
const audioDevice = await navigator.mediaDevices.selectAudioOutput();
console.log(
`${audioDevice.kind}: ${audioDevice.label} id = ${audioDevice.deviceId}`
);
// audiooutput: Realtek Digital Output id = 0wE6fURSZ20H0N2NbxqgowQJLWbwo+5ablCVVJwRM3k=
// Create and play audio on the default device first
const audio = document.createElement('audio');
audio.src = 'https://example.com/audio.mp3';
audio.play();
// Redirect output to the selected device
await audio.setSinkId(audioDevice.deviceId);
});Example — Enumerate permitted audio outputs
After the user has granted permission via selectAudioOutput(), the device appears in enumerateDevices().
const devices = await navigator.mediaDevices.enumerateDevices();
const audioOutputs = devices.filter(d => d.kind === 'audiooutput');
audioOutputs.forEach(device => {
console.log(`${device.label} — ${device.deviceId}`);
});
// React to device connect/disconnect
navigator.mediaDevices.addEventListener('devicechange', async () => {
const updated = await navigator.mediaDevices.enumerateDevices();
const stillConnected = updated.some(d => d.deviceId === currentSinkId);
if (!stillConnected) audio.pause();
});