Getting DOMException with playing video onload


April 2019


4 time


I want to play a video when the website is loaded. For that I am using the following code:

window.onload = function webisteLoaded() {
  var main_bg_video = document.getElementById("main_bg_video");;
<video id="main_bg_video" height="100%" width="100%" autoplay="autoplay">
        <source src="./media/main/main.mp4" type="video/mp4">
        Your browser does not support HTML5 video.

Additional info: I import the script in the <head/> tag. Sometimes, not every time I get this error:

 Uncaught (in promise) DOMException  

The error has the following details:

webisteLoaded   @   main.js:3
load (async)        
(anonymous) @   main.js:1  

Why I get this and how to fix it?

0 answers