JavaScript Navigator getAutoplayPolicy() Method

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

What You’ll Learn

navigator.getAutoplayPolicy() tells you whether media or Web Audio can autoplay: allowed, allowed-muted, or disallowed. Learn type checks (mediaelement / audiocontext), per-element checks, the mute-to-autoplay pattern, five examples, and try-it labs.

01

Kind

Method

02

Returns

Policy string

03

Status

Experimental

04

Types

mediaelement / audiocontext

05

Or pass

video / audio / AudioContext

06

Results

allowed · allowed-muted · disallowed

Introduction

Browsers often block surprise sound on page load. That is why videos with autoplay may start muted, wait for a click, or not start at all.

getAutoplayPolicy() gives your page a clear answer up front so you can mute a video, show a Play button, or leave autoplay alone — instead of guessing.

💡
Check early

MDN recommends calling this on page load (or before creating players), then configuring media from the result. There is no event when the policy later changes.

Understanding the getAutoplayPolicy() Method

  • Call with one argument — a type string, a media element, or an AudioContext.
  • Type "mediaelement" — broad policy for <video> / <audio>.
  • Type "audiocontext" — broad policy for Web Audio API players.
  • "allowed" — autoplay is allowed (including with sound).
  • "allowed-muted" — only inaudible / muted content may autoplay.
  • "disallowed" — autoplay is blocked; offer a play control.

📝 Syntax

General forms of the method:

JavaScript
navigator.getAutoplayPolicy(type)
navigator.getAutoplayPolicy(element)
navigator.getAutoplayPolicy(context)

Parameters

  • type"mediaelement" or "audiocontext".
  • element — an HTMLMediaElement (video / audio).
  • context — an AudioContext.

Return value

  • A string: "allowed", "allowed-muted", or "disallowed".

Common patterns

JavaScript
// MDN: configure based on mediaelement policy
if (navigator.getAutoplayPolicy("mediaelement") === "allowed") {
  // Do nothing. The content can autoplay.
} else if (navigator.getAutoplayPolicy("mediaelement") === "allowed-muted") {
  // Mute the video so it can autoplay.
} else {
  // Autoplay disallowed — add a play button.
}

// Per-element check
const video = document.getElementById("video_element_id");
if (navigator.getAutoplayPolicy(video) === "allowed-muted") {
  video.muted = true;
}

⚡ Quick Reference

GoalCode
Feature detecttypeof navigator.getAutoplayPolicy === "function"
Video / audio type policynavigator.getAutoplayPolicy("mediaelement")
Web Audio type policynavigator.getAutoplayPolicy("audiocontext")
One video elementnavigator.getAutoplayPolicy(video)
Possible resultsallowed · allowed-muted · disallowed

🔍 At a Glance

Four facts to remember about navigator.getAutoplayPolicy().

Returns
string

Policy result

Status
Experimental

Feature-detect

Mute path
allowed-muted

Mute then autoplay

Fallback
Play button

If disallowed / missing

📋 Policy Results Side by Side

ResultMeaningTypical UX
allowedAutoplay OK (with sound)Leave media as-is
allowed-mutedOnly muted / silent autoplaySet muted = true
disallowedAutoplay blockedShow Play control

Examples Gallery

Examples follow MDN Autoplay Policy Detection patterns. Prefer Try It Yourself — results differ by browser and whether the user has already interacted with the site.

📚 Getting Started

Detect the API and read the broad media-element policy.

Example 1 — Feature Detection

MDN-style support check before reading any policy.

JavaScript
if (!navigator.getAutoplayPolicy) {
  console.log("navigator.getAutoplayPolicy() not supported.");
} else {
  console.log("navigator.getAutoplayPolicy() is supported.");
}
Try It Yourself

How It Works

If missing, autoplay behavior is entirely up to the browser — keep a Play button.

Example 2 — Policy for "mediaelement"

Read the broad autoplay policy for video and audio elements.

JavaScript
if (!navigator.getAutoplayPolicy) {
  console.log("getAutoplayPolicy not supported");
} else {
  console.log(
    "mediaelement policy: " + navigator.getAutoplayPolicy("mediaelement")
  );
}
Try It Yourself

How It Works

On first load, this broad type policy usually matches individual media elements.

📈 Practical Patterns

Check Web Audio, mute when needed, and query a specific element.

Example 3 — Policy for "audiocontext"

Check the broad policy for Web Audio API players.

JavaScript
if (!navigator.getAutoplayPolicy) {
  console.log("getAutoplayPolicy not supported");
} else {
  console.log(
    "audiocontext policy: " + navigator.getAutoplayPolicy("audiocontext")
  );
}
Try It Yourself

How It Works

Use this before starting oscillators / buffers without a user gesture.

Example 4 — Mute When allowed-muted

MDN pattern: configure a video so autoplay still works under a muted-only policy.

JavaScript
function configureAutoplayVideo(video) {
  if (!navigator.getAutoplayPolicy) {
    return "API missing — keep a Play button; browser decides autoplay";
  }
  const policy = navigator.getAutoplayPolicy("mediaelement");
  if (policy === "allowed") {
    return "allowed — leave video unmuted";
  }
  if (policy === "allowed-muted") {
    video.muted = true;
    return "allowed-muted — video muted so it can autoplay";
  }
  return "disallowed — show a Play button instead of autoplay";
}

const fakeVideo = { muted: false };
console.log(configureAutoplayVideo(fakeVideo));
console.log("muted = " + fakeVideo.muted);
Try It Yourself

How It Works

Muting under allowed-muted is the most common UX fix for hero videos.

Example 5 — Check a Specific Element

Pass a real media element for a more precise check after user interaction.

JavaScript
const video = document.createElement("video");

if (!navigator.getAutoplayPolicy) {
  console.log("getAutoplayPolicy not supported");
} else {
  const typePolicy = navigator.getAutoplayPolicy("mediaelement");
  const elPolicy = navigator.getAutoplayPolicy(video);
  console.log("type: " + typePolicy);
  console.log("element: " + elPolicy);
  if (elPolicy === "allowed-muted") {
    video.muted = true;
    console.log("Element muted for autoplay");
  }
}
Try It Yourself

How It Works

After interaction, an element check can differ from the broad type policy — prefer it before play().

🚀 Common Use Cases

  • Hero / background videos — mute automatically when policy is allowed-muted.
  • Play button UX — show controls when policy is disallowed.
  • Web Audio apps — check audiocontext before starting sound without a click.
  • Media players — configure autoplay flags from a single policy read on load.
  • Progressive enhancement — feature-detect and never rely on autoplay alone.

🧠 How navigator.getAutoplayPolicy() Works

1

Detect the method

Confirm navigator.getAutoplayPolicy exists.

Detect
2

Ask for a policy

Pass "mediaelement", "audiocontext", or a concrete player.

Query
3

Branch on the result

allowed / allowed-muted / disallowed drive mute or Play UI.

Configure
4

Play without surprise sound

Users get a quieter, clearer experience that matches the browser policy.

📝 Notes

  • Experimental — feature-detect always; keep a Play-button fallback.
  • Not Deprecated or Non-standard — Experimental banner only.
  • No change event — re-check before play if the user may have interacted.
  • Wrong argument types throw TypeError.
  • Related: getBattery(), mediaSession, userActivation, Window.

Limited / Experimental Support

navigator.getAutoplayPolicy() is part of the experimental Autoplay Policy Detection API. Support is limited across browsers. Always feature-detect, configure mute / Play UI from the result, and never assume audible autoplay will work.

Experimental · Limited

Navigator.getAutoplayPolicy()

Returns allowed, allowed-muted, or disallowed for media / Web Audio autoplay.

Limited Experimental
Google Chrome Autoplay Policy Detection where implemented
Limited
Microsoft Edge Follow Chromium support
Limited
Mozilla Firefox Check compatibility — feature-detect
Limited
Apple Safari Check compatibility — feature-detect
Limited
Opera Follow Chromium where available
Limited
Internet Explorer No getAutoplayPolicy support
Unavailable
getAutoplayPolicy() Limited

Bottom line: Detect getAutoplayPolicy, check mediaelement or audiocontext on load, mute when allowed-muted, and always offer a Play control when disallowed or unsupported.

Conclusion

navigator.getAutoplayPolicy() is the experimental way to ask the browser whether media or Web Audio may autoplay. Detect it, read allowed / allowed-muted / disallowed, mute when needed, and always keep a Play button ready.

Continue with getBattery(), mediaSession, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Feature-detect navigator.getAutoplayPolicy
  • Check on page load before configuring players
  • Mute when the policy is allowed-muted
  • Show a Play button when disallowed
  • Prefer per-element checks before play() after interaction

❌ Don’t

  • Assume audible autoplay works everywhere
  • Skip a Play control when the API is missing
  • Expect a change event when policy updates
  • Pass unsupported object types (throws TypeError)
  • Rely on autoplay for critical instructions

Key Takeaways

Knowledge Unlocked

Five things to remember about getAutoplayPolicy()

Ask the browser before you autoplay — mute or show Play.

5
Core concepts
02

Status

Experimental

Limited
🔊 03

Muted path

allowed-muted

Mute
📹 04

Types

mediaelement

audiocontext
🎯 05

Fallback

Play button

UX

❓ Frequently Asked Questions

It returns a string describing whether autoplay is allowed, allowed only when muted (allowed-muted), or disallowed — for media elements / audio contexts as a type, or for a specific HTMLMediaElement or AudioContext.
MDN marks it Experimental. It is not Deprecated or Non-standard. Always feature-detect and keep a play-button fallback when the API is missing.
One of: "allowed", "allowed-muted", or "disallowed".
Autoplay is allowed only for inaudible media — no audio track, or audio that has been muted. Apps often mute a video so it can still autoplay.
MDN recommends calling on page load (or before creating media) to configure autoplay. There is no event when the policy changes after user interaction, so also check again before play if needed.
Passing "mediaelement" returns the broad type policy. Passing a video/audio element returns that item's policy, which can differ after the user has interacted with the page.
Did you know?

There is no event when autoplay policy changes after the user clicks around the page. MDN notes you can check anytime, but most apps only need a load-time check (plus another check right before calling play() if you want to be careful).

Explore getBattery() Next

Read charging state and battery level with the Battery Status API.

getBattery() →

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