How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() javascript javascript

How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause()


For Chrome they changed autoplay policy, so you can read about here:

var promise = document.querySelector('audio').play();if (promise !== undefined) {    promise.then(_ => {        // Autoplay started!    }).catch(error => {        // Autoplay was prevented.        // Show a "Play" button so that user can start playback.    });}


I don't know if this is still actual for you, but I still leave my comment so maybe it will help somebody else.I had same issue, and the solution proposed by @dighan on bountysource.com/issues/solved it for me.

So here is the code that solved my problem:

var media = document.getElementById("YourVideo");const playPromise = media.play();if (playPromise !== null){    playPromise.catch(() => { media.play(); })}

It still throws an error into console, but at least the video is playing :)


Try using a callback like this with the catch block.

document.getElementById("audio").play().catch(function() {    // do something});