CodexBloom - Programming Q&A Platform

HTML `<video>` Element configuration guide to `play()` Method in Edge - Autoplay Policy Issues

πŸ‘€ Views: 51 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-12
html video edge HTML

I've hit a wall trying to I've been banging my head against this for hours... I'm working with an scenario with the `<video>` element where the `play()` method does not seem to work in Microsoft Edge (version 95.0.1020.40) due to the browser's autoplay policy. I've set the video to autoplay, but it doesn't start playing unless I interact with the page first. Here’s the code I’m using: ```html <video id="myVideo" controls autoplay muted> <source src="video.mp4" type="video/mp4"> Your browser does not support the video tag. </video> ``` I’ve also tried adding the `muted` attribute, which should allow the video to play automatically, but it still doesn't trigger the play action. When I attempt to call `document.getElementById('myVideo').play()`, I see a console behavior: "Uncaught (in promise) DOMException: Play can only be initiated by a user gesture." I understand that the autoplay policy in Edge requires user interaction if the video is not muted, but my video is muted. I've verified this on other browsers like Chrome and Firefox, and it works perfectly. I've also experimented with setting the video to start playing in a `DOMContentLoaded` event listener, but that hasn't resolved the scenario either: ```javascript document.addEventListener('DOMContentLoaded', function() { const video = document.getElementById('myVideo'); video.play().catch((behavior) => { console.behavior('behavior trying to play the video:', behavior); }); }); ``` Is there a specific configuration or workaround needed for Edge? Any insights on making the video play without requiring explicit user interaction would be greatly appreciated. How would you solve this? The project is a CLI tool built with Html. Am I missing something obvious?