小编use*_*154的帖子

用于嵌入 YouTube 视频的 CSP

我刚刚开始在 Chrome 上的嵌入式 YouTube 视频中看到这一点(86.0.4240.193 - 最近更新,这可能就是我看到这个的原因) - 这些只是“报告”,因此视频仍然会显示,但可能会出现数百个错误不对吧!这就是我所看到的:

[Report Only] Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'strict-dynamic' 'unsafe-inline' https: 'report-sample' 'nonce-t9IE7nI2leo7qKxsm7d80g=='".
Run Code Online (Sandbox Code Playgroud)

这是我的 iFrame——

<iframe id="video-iframe" width="500" height="281" src="https://www.youtube.com/embed/HIDDENVIDEO" frameborder="0" allowfullscreen ></iframe>
Run Code Online (Sandbox Code Playgroud)

我不知道 CSP 应该是什么——我发现这个 CSP 显然可以解决他们的问题——

<iframe id="video-iframe" width="500" height="281" src="https://www.youtube.com/embed/HIDDENVIDEO" frameborder="0" allowfullscreen csp="script-src 'self' https://www.google-analytics.com/ https://www.youtube.com/ https://s.ytimg.com/; object-src 'self'; child-src https://www.youtube.com/* https://s.ytimg.com/"></iframe>
Run Code Online (Sandbox Code Playgroud)

没那么多——我只是看到:拒绝显示......

非常感谢任何帮助。

我刚刚检查了该developers.google.com/youtube/iframe_api_reference#Examples页面,我看到了同样的事情——这当然不应该发生,对吧?

在此输入图像描述

content-security-policy youtube-iframe-api

7
推荐指数
1
解决办法
2万
查看次数