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 to the video element.
}Navigator: getAutoplayPolicy() method / notebook
Navigator: getAutoplayPolicy() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const video = document.getElementById("video_element_id");
if (navigator.getAutoplayPolicy(video) === "allowed") {
// Do nothing. The content can autoplay.
} else if (navigator.getAutoplayPolicy(video) === "allowed-muted") {
// Mute the video so it can autoplay.
} else {
// Autoplay disallowed.
// Add a play button to the video element.
}