Search code examples
google-chromehtml5-audioweb-audio-api

How can I enable autoplay in Chrome?


I am making a Chrome Extension and "autoplay" is essential to it.

The extension is a kind of audio player. It lets me add sites to a playlist and the extension will automatically go to each of those URLs and play their content in order.

Since the program needs to go from one element in the playlist to the next seamlessly, I can't require user interaction.

I wanted to enable autoplay in MY OWN browser so that I could at least use the software personally, but I can't even figure out how to do that.

Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first. https://developers.google.com/web/updates/2017/09/autoplay-policy-changes

On that link it says to go to chrome://flags/#autoplay-policy but this flag doesn't seem to exist.

Chrome Version 78.0.3904.108 (Official Build) (64-bit)


Note

I found a workaround, which is keep the actual audio player page alive and load the other pages in an iframe. This only works because they don't enforce same-origin policy. However I'm still curious if there's a way to disable the whole autoplay restriction.


Solution

  • It's possible to start Chrome with a flag that turns off the autoplay policy. Unfortunately this can only be done via the command line. At least as far as I know.

    On macOS it looks like this:

    /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --autoplay-policy=no-user-gesture-required
    

    It's a bit different for other operating systems. But there is an official guide which explains how to start Chromium (or Chrome) from the command line on Windows or Linux.

    The setting will not persist. The next time you start Chrome without that flag it will have the autoplay policy enabled again.