DOMException: play() failed because the user didn‘t interact with the document first

error is due to the new feature of chrome, which basically means that developers cannot use their permissions to cause noise interference to users, and users need to interact with audio/video

to load the page for the first time

The requirements are as follows:
refresh the alarm list in real time to ensure the user gets the latest alarm message. When there is a new alarm message, sound the alarm bell

solution

enable alarm bell to prompt users when they first enter the page

let audioPlay = document.getElementById('myaudio')

audioPlay.play()

setTimeout(() => {
  audioPlay.pause()
  audioPlay.load()
}, 10)

click to interact with audio for the first time, set 10 milliseconds and the user will not hear the bell. Set the alarm time to

when using again

Read More: