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 Session API
ExperimentalProvides a mechanism for web applications to express the nature of their audio output so the platform can manage how it interacts with other audio on the device — ducking, pausing, or routing through the appropriate hardware.
Key Interface
Navigator.audioSession— Returns theAudioSessionobject for the current document.AudioSession.type— Sets/gets the session type. Defaults to"auto".
Session Types
| Type | Use case |
|---|---|
"auto" | Default. Browser infers the best type automatically. |
"playback" | Music or video — should not mix with other playback. |
"transient" | Short sounds (notifications) — plays on top of other audio. |
"transient-solo" | Voice prompts — pauses all other audio while playing. |
"ambient" | Background audio — can mix freely with other audio. |
"play-and-record" | Video conferencing — simultaneous playback and capture. |
Example — Video conferencing session
Set the session type to "play-and-record" so the platform can route audio appropriately (e.g. earpiece on mobile) and prevent other apps from interrupting the call.
// Declare play-and-record intent before starting media streams
navigator.audioSession.type = 'play-and-record';
// Start playing remote participant audio/video
remoteVideo.srcObject = remoteMediaStream;
remoteVideo.play();
// Capture local audio and video
navigator.mediaDevices
.getUserMedia({ audio: true, video: true })
.then((stream) => {
localVideo.srcObject = stream;
});Example — Music playback
Declare a "playback" session so the platform treats it like a media player — allowing hardware media keys to control it and preventing it from mixing with other playback audio.
navigator.audioSession.type = 'playback';
const audio = new Audio('https://example.com/track.mp3');
audio.play();
// React to platform-level interruptions (e.g. incoming call)
navigator.audioSession.addEventListener('statechange', () => {
if (navigator.audioSession.state === 'interrupted') {
audio.pause();
} else if (navigator.audioSession.state === 'active') {
audio.play();
}
});