且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何处理“未捕获(承诺)DOMException:play() 失败,因为用户没有先与文档交互."在 Chrome 66 的桌面上?

更新时间:2021-08-23 21:11:59

要使 html 5 元素在 chrome 66 更新后自动播放,您只需将 muted 属性添加到视频元素.

To make the autoplay on html 5 elements work after the chrome 66 update you just need to add the muted property to the video element.

所以你当前的视频 HTML

So your current video HTML

<video
    title="Advertisement"
    webkit-playsinline="true"
    playsinline="true"
    style="background-color: rgb(0, 0, 0); position: absolute; width: 640px; height: 360px;"
    src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
    autoplay=""></video>

只需要muted="muted"

<video
    title="Advertisement"
    style="background-color: rgb(0, 0, 0); position: absolute; width: 640px; height: 360px;"
    src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
    autoplay="true"
    muted="muted"></video>

我相信 chrome 66 更新试图阻止标签在用户标签上产生随机噪音.这就是静音属性使自动播放再次工作的原因.

I believe the chrome 66 update is trying to stop tabs creating random noise on the users tabs. That's why the muted property make the autoplay work again.