JavaScript Navigator getAutoplayPolicy() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Method

Definition

navigator.getAutoplayPolicy() reports whether autoplay of media or Web Audio is allowed, allowed-muted, or disallowed (MDN). Use it to mute videos or show a Play button instead of guessing the browser’s rules.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call navigator.getAutoplayPolicy. Start with this line.

JavaScript
navigator.getAutoplayPolicy(arg)
CallWhat it does
navigator.getAutoplayPolicy(arg)Primary signature.
navigator.getAutoplayPolicy(...)Call with the arguments your case needs.

Built into the browser. Call getAutoplayPolicy(...) on a Navigator — no import required.

Library declarations
JavaScript
navigator.getAutoplayPolicy(arg)

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*"allowed" | "allowed-muted" | "disallowed"

JavaScript Examples

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

  1. Test the method. A missing property means you cannot query policy.
  2. Expect gaps. Support is limited — Chrome/Safari often lack it.
  3. Plan a fallback. Keep a Play button when the API is missing.
  4. Then branch. Only call the method after this check passes.

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

  1. Pass the type string. "mediaelement" covers <video> / <audio>.
  2. Read one of three results. allowed, allowed-muted, or disallowed.
  3. Use it on load. Configure mute / Play before media is created when possible.
  4. Match on first load. Broad type policy usually matches each element initially.

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

  1. Use a different type. Web Audio is not covered by "mediaelement".
  2. Read before starting sound. Oscillators / buffers often need a gesture.
  3. Same three strings. Interpret them the same way as for media elements.
  4. Offer a Start button. When disallowed, wait for a click to resume audio.

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

  1. Guard the API. Missing → do not assume mute or autoplay.
  2. Read the type policy. One call drives the UX branch.
  3. Mute for allowed-muted. Inaudible media can still autoplay.
  4. Show Play when disallowed. Never rely on silent failure of play().

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

  1. Create or select an element. Pass that object, not the type string.
  2. Compare with the type. On first load they usually match.
  3. Prefer element before play. After interaction, it can be more accurate.
  4. Apply mute to that element. Same allowed-muted rule as the type check.

Browser Support

navigator.getAutoplayPolicy() is part of the Autoplay Policy Detection API. MDN marks it Experimental and not Baseline. Strongest on Firefox (~112+); many Chromium and Safari builds do not expose it. Always feature-detect.

✓ Experimental · Not Baseline

Navigator.getAutoplayPolicy()

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

Limited Experimental
Mozilla Firefox getAutoplayPolicy from ~112+
Supported
Google Chrome Often missing — feature-detect
Unavailable
Microsoft Edge Often missing — feature-detect
Unavailable
Apple Safari No support (typical)
Unavailable
Opera Follow Chromium — usually missing
Unavailable
Internet Explorer No support
Unavailable
getAutoplayPolicy() Limited

Bottom line: Detect the API, configure mute or Play from the result, and never depend on autoplay alone when the method is missing.

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.

Next: getBattery()

Learn how to read battery level and charging state from Navigator.

getBattery() tutorial →

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.

7 people found this page helpful