JavaScript Navigator audioSession Property

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Experimental

What You’ll Learn

navigator.audioSession returns the document’s AudioSession object. Set type to tell the platform whether you are playing music, showing a short sound, or running a call. Learn feature detection, common types, five examples, and try-it labs.

01

Kind

Read-only property

02

Returns

AudioSession

03

Status

Experimental

04

Key knob

.type

05

Baseline

Not yet

06

Detect

in navigator

Introduction

Phones and desktops constantly mix sounds: music, maps, notifications, and video calls. The Audio Session API lets a web page declare the kind of audio it produces so the OS can pause, duck, or mix other audio appropriately.

Your entry point is navigator.audioSession. That property is read-only and returns an AudioSession object. You usually set navigator.audioSession.type before starting playback or a call.

💡
Optional enhancement

Missing support does not break media. Without audioSession, browsers still play audio — you just cannot send a session-type hint.

Understanding the audioSession Property

Think of audioSession as a handle to policy settings for this document’s audio. The most important setting today is type.

  • navigator.audioSession is read-only and returns an AudioSession.
  • AudioSession.type is readable and writable when the API exists.
  • Types describe intent: playback, transient sounds, ambient mix, or play-and-record.
  • Always feature-detect — the API is experimental and not Baseline.

📝 Syntax

General form of the property:

JavaScript
navigator.audioSession

Value

  • An AudioSession object for the current document.

Common type values (MDN)

  • "auto" — default; user agent chooses.
  • "playback" — music / video / podcasts (often exclusive vs other playback).
  • "transient" — short sounds; may duck other audio.
  • "transient-solo" — exclusive prompts (for example directions).
  • "ambient" — mixes with other audio.
  • "play-and-record" — calls / mic + playback.

Common patterns

JavaScript
if ("audioSession" in navigator) {
  navigator.audioSession.type = "play-and-record";
}

// Then start media / getUserMedia as usual
const stream = await navigator.mediaDevices.getUserMedia({
  audio: true,
  video: true
});

⚡ Quick Reference

GoalCode
Feature detect"audioSession" in navigator
Get the sessionnavigator.audioSession
Read typenavigator.audioSession.type
Music / videotype = "playback"
Notification beeptype = "transient"
Video calltype = "play-and-record"

🔍 At a Glance

Four facts to remember about audioSession.

Returns
AudioSession

Per document

Status
experimental

Not Baseline

Control
.type

Set intent

Missing?
OK

Audio still works

📋 Common type values

TypeTypical usePlatform behavior (approx.)
autoDefaultUA decides from APIs you use
playbackMusic, video, podcastsMay pause other playback audio
transientNotificationsOften ducks other audio
transient-soloVoice prompts / directionsExclusive; others may pause
ambientBackground mixMixes with other audio
play-and-recordCalls / mic + mediaSimultaneous capture + playback

Examples Gallery

Examples follow MDN Navigator.audioSession patterns with safe feature detection. Use View Output or Try It Yourself for each case.

📚 Getting Started

Detect support and read the current type safely.

Example 1 — Feature Detection

Check whether audioSession exists before using it.

JavaScript
const supported = "audioSession" in navigator;
console.log(supported ? "audioSession available" : "audioSession missing");
Try It Yourself

How It Works

Most desktop browsers still omit the API. Detection keeps demos and production code safe.

Example 2 — Read Current type

When supported, log the session type (often "auto" by default).

JavaScript
if (!("audioSession" in navigator)) {
  console.log("audioSession not supported");
} else {
  console.log("type: " + navigator.audioSession.type);
}
Try It Yourself

How It Works

Reading type without detection would throw on unsupported browsers.

📈 Practical Patterns

Set types for playback, calls, and a reusable helper.

Example 3 — Set "playback" for Media

MDN: declare music/video intent before playing.

JavaScript
function preparePlayback() {
  if ("audioSession" in navigator) {
    navigator.audioSession.type = "playback";
    return "set type=playback";
  }
  return "skipped (no audioSession)";
}

console.log(preparePlayback());
// Then: audioElement.play()
Try It Yourself

How It Works

On supporting platforms, "playback" can pause other playback audio while your media runs.

Example 4 — "play-and-record" for Calls

Set the type before starting camera/mic for a conference-style flow.

JavaScript
async function startCallPreview() {
  if ("audioSession" in navigator) {
    navigator.audioSession.type = "play-and-record";
  }
  // Demo only logs intent — real apps call getUserMedia next
  return "ready for getUserMedia (audio+video)";
}

startCallPreview().then(console.log);
Try It Yourself

How It Works

MDN’s conferencing pattern: set play-and-record, then capture local media and play remote media.

Example 5 — Safe Setter Helper

Centralize detection so call sites stay clean.

JavaScript
function setAudioSessionType(type) {
  if (!("audioSession" in navigator)) {
    return { ok: false, reason: "unsupported" };
  }
  navigator.audioSession.type = type;
  return { ok: true, type: navigator.audioSession.type };
}

const result = setAudioSessionType("transient");
console.log(JSON.stringify(result));
// {"ok":false,"reason":"unsupported"}
// or {"ok":true,"type":"transient"}
Try It Yourself

How It Works

Use "transient" for short notification sounds that may duck other audio.

🚀 Common Use Cases

  • Music / video players"playback" before play().
  • Notifications"transient" for short UI sounds.
  • Navigation prompts"transient-solo" for exclusive voice guidance.
  • Video conferencing"play-and-record" with mic + remote audio.
  • Ambient / mix experiences"ambient" when mixing is desired.
  • Progressive enhancement — set type only when the API exists.

🧠 How audioSession Works

1

Feature-detect

Confirm "audioSession" in navigator.

Detect
2

Set session type

Assign navigator.audioSession.type for your scenario.

Type
3

Start media

Play elements, Web Audio, or getUserMedia as usual.

Media
4

Platform mixes audio

OS may pause, duck, or mix other apps based on your type.

📝 Notes

  • Experimental and not Baseline — support is limited.
  • navigator.audioSession is read-only; configure via .type.
  • Missing API is fine — media APIs still work without it.
  • Set the type before starting the relevant media when possible.
  • Related: appVersion, Window, JavaScript hub.

Limited Browser Support

navigator.audioSession is Experimental and not Baseline. Many widely used browsers do not expose it yet. Feature-detect and treat it as progressive enhancement.

Experimental · Not Baseline

Navigator.audioSession

Useful on supporting platforms for audio policy hints. Always detect before reading or setting type.

Limited Not Baseline
Google Chrome Check current MDN compat — limited / evolving
Limited
Mozilla Firefox Check current MDN compat — may be unavailable
Limited
Apple Safari Related Audio Session work may appear on some platforms
Limited
Microsoft Edge Follow Chromium Audio Session status
Limited
Opera Follow Chromium status
Limited
Internet Explorer No Audio Session API
Unavailable
audioSession Limited

Bottom line: Use audioSession when available to declare playback vs call intent. Never require it for core media features.

Conclusion

navigator.audioSession is the experimental entry point to the Audio Session API. Feature-detect it, set type for playback or calls when available, and keep your media code working without it.

Continue with bluetooth, Window methods, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect before every use
  • Set type before starting media/calls
  • Match type to real intent (playback vs call)
  • Treat the API as progressive enhancement
  • Recheck MDN compatibility often

❌ Don’t

  • Assume Baseline support across browsers
  • Crash if audioSession is undefined
  • Require the API for core playback
  • Confuse read-only audioSession with writable type
  • Skip microphone permission UX for calls

Key Takeaways

Knowledge Unlocked

Five things to remember about audioSession

Experimental AudioSession handle — set type, detect first.

5
Core concepts
🔧 02

type

set intent

Control
🧪 03

Status

experimental

Caution
🔍 04

Detect

in navigator

Safety
📞 05

Calls

play-and-record

Pattern

❓ Frequently Asked Questions

It is a read-only Navigator property that returns the AudioSession object for the current document. You use that object to declare how your page's audio should interact with other audio on the device.
Yes. MDN marks it Experimental and not Baseline. Always feature-detect before using it, and check the compatibility table before shipping to production.
Assign navigator.audioSession.type to a string such as "playback", "transient", "ambient", or "play-and-record". The default is "auto".
For video calls or any flow that needs simultaneous playback and microphone capture. Set the type before starting getUserMedia or remote media when possible.
No. The property is read-only and returns an AudioSession. You change behavior by setting AudioSession.type on that object.
Your audio still works with normal media APIs. The platform simply will not receive your Audio Session type hint. Feature-detect and treat the API as an optional enhancement.
Did you know?

On some mobile platforms, "play-and-record" can influence routing (for example earpiece vs loudspeaker) during a call — that is why declaring session type before getUserMedia matters when the API is available.

Learn bluetooth Next

Experimental Web Bluetooth entry on Navigator.

bluetooth →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful