Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

326
Views
DOMException: play() failed because the user didn't interact with the document first

I keep getting this error that says "DOMException: play() failed because the user didn't interact with the document first." but, I don't know what to do. Any suggestions?

<script>
var audioElement = new Audio();
audioElement.setTrack("assets/music/bensound-acousticbreeze.mp3");
audioElement.audio.play();

</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Hi I'm completely new here, but I seem to have found the answer to this.

That error means that in newest version of Chrome sounds are not allowed to play until the user interacts with the webpage.

So all I did (having had the same issue and stumbling upon your question)

I simply attached the sound to a click (as its my intended design anyway), but if you want to play some music as intro you might need to introduce like a "start" button before that menu or otherwise a check that plays the sound when user interacts with the website.

Sorry that I'm not super technical about this, I am learning also and I hope this helps.

https://gamedev.stackexchange.com/questions/163365/html5-games-play-failed-because-the-user-didnt-interact-with-the-document-fi

If it helps here's a video of how I solved my problem:

https://recordit.co/iMmQ0BCbyN

In the video the sound finally plays when I click but would throw an error when I try to play it on load...

Cheers

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!