YouTube 是如何运作的?
How does YouTube work?
Google Chrome 不遵守 HTML5 <video>
元素上的 autoplay
属性。在页面加载后立即使用 video.play()
JavaScript 会引发错误:
Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.
好的,但 YouTube 视频 HTML5 并且自动播放效果很好。 YouTube 使用什么技术来绕过 Chrome 的限制? 是否所有网页都可以这样做(或者不可以,可能是因为 YouTube 自 Google 以来有一个例外)拥有它)?
对于 Youtube,它可能是一个预填充的白名单
https://blog.google/products/chrome/improving-autoplay-chrome/
If you don’t have browsing history, Chrome allows autoplay for over 1,000 sites where we see that the highest percentage of visitors play media with sound.
其他情况可以参考以下规则(至少Chrome)
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
Autoplay with sound is allowed if:
User has interacted with the domain (click, tap, etc.).
On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound.
Google Chrome 不遵守 HTML5 <video>
元素上的 autoplay
属性。在页面加载后立即使用 video.play()
JavaScript 会引发错误:
Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.
好的,但 YouTube 视频 HTML5 并且自动播放效果很好。 YouTube 使用什么技术来绕过 Chrome 的限制? 是否所有网页都可以这样做(或者不可以,可能是因为 YouTube 自 Google 以来有一个例外)拥有它)?
对于 Youtube,它可能是一个预填充的白名单
https://blog.google/products/chrome/improving-autoplay-chrome/
If you don’t have browsing history, Chrome allows autoplay for over 1,000 sites where we see that the highest percentage of visitors play media with sound.
其他情况可以参考以下规则(至少Chrome)
https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
Autoplay with sound is allowed if:
User has interacted with the domain (click, tap, etc.).
On desktop, the user's Media Engagement Index threshold has been crossed, meaning the user has previously played video with sound.