Video autoplay blocked: play() NotAllowedError, muted and playsinline
Our landing page hero video played on desktop and stayed frozen on most phones, with an uncaught NotAllowedError in the console. Autoplay policies only allow muted inline video without a gesture. Muted, playsinline and handling the play() promise fixed it.
The marketing team launched a new landing page with a short looping product video as the hero. On the designers' Macs it played instantly. On iPhones it showed the first frame and stayed still. On Android, it played for some testers and not others. Error tracking had thousands of unhandled promise rejections from the hero component:
NotAllowedError: play() failed because the user didn't interact with the document first.
https://goo.gl/xX8pDD
Safari reported its generic version:
NotAllowedError: The request is not allowed by the user agent or the platform in the current
context, possibly because the user denied permission.
Reproducing it
The component, simplified:
<video id="hero" src="/media/hero.mp4" loop preload="auto" poster="/media/hero.jpg"></video>
<script>
document.getElementById('hero').play();
</script>
Open it in a fresh Chrome profile or on any iPhone: no playback, and the rejection appears. Open it in a Chrome profile that has visited the site often: it may play.
What we ruled out
Codec support. The same file played fine when we tapped it, so decoding was not the problem.
Loading.
canplaythroughfired; the video was buffered.Low Power Mode alone. It explained a few iPhone reports, but most testers had it off.
A content blocker. Fresh devices without extensions reproduced it.
Root cause
The video had an audio track and was not muted. Every major browser blocks autoplay of video with sound unless the user has interacted with the page or the site has earned an exception. Calling play() without a gesture returned a rejected promise that our code never handled. On iOS there was a second problem: without playsinline, iPhone Safari only plays video full screen, which it never does automatically.
What is happening under the hood
Autoplay policies exist so pages cannot blast sound at users. The shared rule across engines: muted video may autoplay; video with sound needs a user gesture or a site-level allowance. Details differ:
Chrome allows autoplay with sound after a user interaction with the domain, when the site's Media Engagement Index is high enough (the user often watches media with sound there), or for installed web apps on some platforms. You can inspect the index at
chrome://media-engagement. That is why frequent visitors saw it play.Safari allows muted autoplay and lets users choose per site in Settings for Websites, Auto-Play ("Allow All Auto-Play", "Stop Media with Sound", "Never Auto-Play"). On iPhone, inline playback requires the
playsinlineattribute. Low Power Mode can stop autoplay even for muted video.Firefox blocks audible autoplay by default, with a per-site setting in the address bar.
HTMLMediaElement.play() returns a promise. When the browser blocks playback, the promise rejects with NotAllowedError. If nobody catches it, you get an unhandled rejection and no fallback UI.
The autoplay attribute follows the same rules; it does not grant more than a play() call.
Environment
Component | Version / value |
|---|---|
iPhone | iOS 26.1, Safari 26.1 |
Android | Android 16, Chrome 142 |
Desktop | Chrome 142, Firefox 145, Safari 26.1 on macOS Tahoe |
Media | 8-second H.264 MP4 with an AAC audio track, 1.8 MB |
App | Astro 5 landing page |
Minimal reproduction
<!-- blocked: has audio, not muted, not inline -->
<video src="/media/hero.mp4" autoplay loop></video>
<!-- allowed everywhere autoplay is not disabled by the user -->
<video src="/media/hero.mp4" autoplay muted loop playsinline></video>
Who is affected
Hero and background videos, product loops, video previews on hover.
Pages that call
play()on load or after an async fetch (which also loses the user gesture).iOS without
playsinline, even when muted.Users who set "Never Auto-Play" in Safari or disable autoplay in Firefox; nothing overrides that.
The fix
The hero video does not need sound, so we stripped the audio track and made the element explicitly muted and inline:
-<video id="hero" src="/media/hero.mp4" loop preload="auto" poster="/media/hero.jpg"></video>
+<video id="hero" src="/media/hero.mp4" poster="/media/hero.jpg"
+ autoplay muted loop playsinline preload="metadata"
+ aria-hidden="true"></video>
# Remove the audio track without re-encoding the video
ffmpeg -i hero-src.mp4 -c:v copy -an -movflags +faststart hero.mp4
Removing the track matters for some browsers' heuristics, and it saves bytes. The muted attribute sets the default; for frameworks that set properties instead of attributes, also set video.muted = true before calling play().
Then we handled the promise, so a block shows a play button instead of a dead frame:
export async function startHero(video: HTMLVideoElement, button: HTMLButtonElement) {
video.muted = true;
try {
await video.play();
button.hidden = true;
} catch (err) {
if ((err as DOMException).name === 'NotAllowedError') {
button.hidden = false; // user disabled autoplay or Low Power Mode
button.onclick = () => video.play().then(() => (button.hidden = true));
return;
}
throw err; // AbortError, NotSupportedError: real problems
}
}
Respecting reduced motion
A looping hero video is also motion that some users ask to avoid. We pause it for them:
if (matchMedia('(prefers-reduced-motion: reduce)').matches) {
video.removeAttribute('autoplay');
video.pause();
}
Videos that need sound
For the product demo further down the page, which has narration, we do not autoplay. A click on the play button starts it with sound, inside the gesture. If you must start muted and offer sound, show a clear "Tap for sound" control that sets video.muted = false in its click handler.
Alternatives and trade-offs
Animated image formats (animated WebP or AVIF) autoplay without policy checks, but files are larger and there are no playback controls.
CSS or Lottie animation for simple motion: tiny and policy-free, but not suitable for real footage.
Poster image only on mobile. Saves data on cellular, at the cost of the effect.
How to test the fix
Fresh Chrome profile (no engagement history): video autoplays muted.
iPhone Safari: plays inline, not full screen.
iPhone in Low Power Mode: play button appears, tap starts playback.
Safari setting "Never Auto-Play" for the site: play button appears.
Firefox with autoplay blocked for the site: muted video plays; the narrated demo waits for a click.
test('hero autoplays muted', async ({ page }) => {
await page.goto('/');
const state = await page.$eval('#hero', (v: HTMLVideoElement) => ({ paused: v.paused, muted: v.muted }));
expect(state).toEqual({ paused: false, muted: true });
});
Confirming in production
unhandled_rejection{name="NotAllowedError", component="hero"} before: ~9,000/day after: 0
hero_playing_after_2s{os="iOS"} before: 3% after: 91%
hero_fallback_button_shown{os="iOS"} after: 8%
The fallback share on iOS matches roughly the proportion of users with Low Power Mode or autoplay disabled, which is the behaviour we want.
Regression guard
Our
<HeroVideo>component is the only way to place an autoplaying video, and it always setsmuted,playsinlineand the promise handler.A lint rule flags
.play()calls whose promise is not awaited or caught.The media pipeline strips audio for files tagged as background loops.
Security implications
None for data. Autoplay policies protect users from unwanted sound and data usage; do not try to bypass them with tricks such as unmuting right after autoplay starts, which browsers detect and pause. Background videos cost mobile data, so keep them short, compressed and preload="metadata", and do not autoplay large files on save-data connections (navigator.connection?.saveData where available).
Prevention checklist
Autoplay only muted, inline video:
autoplay muted playsinline.Strip audio tracks from decorative loops.
Always handle the
play()promise and show a play button onNotAllowedError.Honour
prefers-reduced-motion.Start videos with sound only from a user gesture.
References
MDN, Autoplay guide for media and Web Audio APIs: https://developer.mozilla.org/en-US/docs/Web/Media/Guides/Autoplay
MDN, HTMLMediaElement.play(): https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play
Chrome for Developers, Autoplay policy in Chrome: https://developer.chrome.com/blog/autoplay
WebKit blog, New video policies for iOS: https://webkit.org/blog/6784/new-video-policies-for-ios/
MDN, prefers-reduced-motion: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion
Add a label
Embed this post
<iframe src="https://hibug.me/video-autoplay-blocked-muted-playsinline" width="700" height="420" frameborder="0" loading="lazy"></iframe>
I work on performance and capacity for a marketplace with heavy read traffic and sharp daily peaks. My days are split between caches, Redis, document stores, connection pools and the load tests that tell us whether any of it will hold. Most of the problems I write about looked like scaling issues and turned out to be something smaller: a cache that refilled itself with stale data, a single command that froze Redis, a pool drained by one leaked connection, a load test that measured its own generator instead of the system. I try hard to measure before changing anything, so each post includes how we gathered numbers, what they showed and how we confirmed the fix under realistic load. I also include the optimisations that made things worse, because those taught me the most.
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.