javascript - Chrome 扩展与网站的 Content-Security-Policy “object-src 'self' blob:”
问题描述
我正在编写一个 chrome 扩展,它利用<object>
内容脚本中的一个从我的中央服务器加载内容以显示给用户。data
在某些网站上,我在 上设置属性的尝试<object>
被阻止,出现以下错误:
Refused to load plugin data from 'https://redacted.com/?url=https%3A%2F%2Fwww.mozilla.org%2Fen-US%2Ffirefox%2F' because it violates the following Content Security Policy directive: "default-src 'self' *.mozilla.net *.mozilla.org *.mozilla.com". Note that 'object-src' was not explicitly set, so 'default-src' is used as a fallback.
我的扩展在 stackoverflow.com 上没有问题!请注意,有时它是object-src 'self' blob:
相反的。
从我的扩展程序尝试加载的网站的响应标头中,很明显这就是阻止我的扩展程序能够执行其工作的原因(stackoverflow.com 中缺少这些标头,这就是它起作用的原因):
content-security-policy: default-src 'self' *.mozilla.net *.mozilla.org *.mozilla.com; child-src www.googletagmanager.com www.google-analytics.com www.youtube-nocookie.com trackertest.org www.surveygizmo.com accounts.firefox.com accounts.firefox.com.cn www.youtube.com; script-src 'self' *.mozilla.net *.mozilla.org *.mozilla.com 'unsafe-inline' 'unsafe-eval' www.googletagmanager.com www.google-analytics.com tagmanager.google.com www.youtube.com s.ytimg.com; style-src 'self' *.mozilla.net *.mozilla.org *.mozilla.com 'unsafe-inline'; img-src 'self' *.mozilla.net *.mozilla.org *.mozilla.com data: mozilla.org www.googletagmanager.com www.google-analytics.com adservice.google.com adservice.google.de adservice.google.dk creativecommons.org ad.doubleclick.net; frame-src www.googletagmanager.com www.google-analytics.com www.youtube-nocookie.com trackertest.org www.surveygizmo.com accounts.firefox.com accounts.firefox.com.cn www.youtube.com; connect-src 'self' *.mozilla.net *.mozilla.org *.mozilla.com www.googletagmanager.com www.google-analytics.com https://accounts.firefox.com/ https://accounts.firefox.com.cn/
有没有解决的办法?Shadow DOM 会是一种选择吗?我已经尝试添加content_security_policy
到我的manifest.json
,但这永远不会起作用,因为浏览器尊重父网站在其标题中响应的内容。
提前致谢。
解决方案
推荐阅读
- regex - 数据框熊猫中的正则表达式
- github - GitHub深色主题在站点更改中闪烁
- android-studio - Android工作室:找不到包androidx.activity.result
- c - 在c中,“p = p->next”是否有“+=”的等价物?
- java - Android 11 摄像头无法在 webview 上运行:不支持的 mime image/vnd.android.heic
- deployment - Visual Studio 2019 安装程序项目:如何删除 .NET Framework 的启动条件
- mysql - Mysql从命令行将数据导出为JSON不起作用
- reactjs - 同步响应更新状态
- java - 无法连接到电子邮件主机以在 linux 环境下阅读电子邮件
- javascript - 如何将多个 $lookup 与对象数组一起使用