gpt4 book ai didi

youtube-api - 在沙箱 iframe 中嵌入 youtube-iframe 失败

转载 作者:行者123 更新时间:2023-12-04 17:31:02 28 4
gpt4 key购买 nike

当将一个 youtube-iframe 嵌入到另一个被沙盒化(以防止 XSS)的 iframe 中时,播放器在所有主要浏览器中都保持黑色。

https://jsfiddle.net/ms9fwLbk/

<!DOCTYPE html><html lang='en'><head><title>Sandbox iframe youtube problem</title></head><body>
<iframe sandbox='allow-scripts allow-presentation' width='600' height='400' srcdoc='
<!DOCTYPE html><html lang="en"><head><title>iframe</title></head><body>
<!-- original source-code shared from youtube: -->
<iframe width="560" height="315"
src="https://www.youtube.com/embed/QwS1r1mc888?controls=0"
frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
</body></html>
'></iframe></body></html>

浏览器的控制台日志显示以下错误,因为 youtube-api 有 CORS 问题
(这里没有允许同源的选项,因为启用了允许脚本并且会使 cookie 容易受到攻击)
Uncaught DOMException: Failed to read the 'cookie' property from 'Document':
The document is sandboxed and lacks the 'allow-same-origin' flag.
at Vb.m.get (https://www.youtube.com/yts/jsbin/www-embed-player-vflwaq4V_/www-embed-player.js:142:47)
Access to XMLHttpRequest at 'https://www.youtube.com/error_204?...'
from origin 'null' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.

它没有帮助
  • 在沙箱中允许更多功能,或者也在内部 iframe 上定义沙箱
  • 使用 youtube 的旧对象嵌入源代码
  • 从 youtube 播放器中删除允许参数
  • 使用 youtube-nocookie.com 应用增强的隐私模式

  • 如何让 youtube 忽略 cookie-access- 或 preflight-origin-limitations?

    (Vimeo 在这样的沙盒 iframe 中没有问题,但有些视频只能在 youtube 上使用。)

    最佳答案

    我遇到了同样的问题,必须设置以下沙箱属性才能使其工作
    沙盒=“允许脚本允许同源”
    更多信息 https://www.w3schools.com/tags/att_iframe_sandbox.asp

    关于youtube-api - 在沙箱 iframe 中嵌入 youtube-iframe 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59827851/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com