在公共页面上忽略了Chrome扩展清单CSP
Chrome extension manifest CSP ignored on public page
我已经将扩展的CSP设置为允许从localhost
加载(理论上):
"content_security_policy": "script-src 'self' 'unsafe-eval' https://localhost:* ws://localhost:* https://*.mysite.com; object-src 'self'",
我有一个web_accessible_resource
,它试图加载并执行远程脚本:
<html>
<head>
<title>Sign in</title>
</head>
<body>
<script src="./auth.js"></script>
</body>
</html>
auth.js
:的(简化)内容
(function(doc, script) {
script = doc.createElement('script')
script.type = 'text/javascript'
script.async = true
script.src = 'https://localhost:3333/remote-server/auth.js'
doc.getElementsByTagName('head')[0].appendChild(script)
}(document))
然而,我得到了以下错误:
Refused to load the script 'https://localhost:3333/remote-server/auth.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
这似乎不尊重扩展的CSP。我试着直接将下面的标题添加到HTML中,但仍然没有什么乐趣。
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-eval' https://localhost:* ws://localhost:* https://*.mysite.com">
是否有其他地方需要我指示CSP?
更新
更改资源的HTML以直接加载远程脚本也没有解决问题:
<html>
<head>
<title>Sign in</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-eval' https://localhost:* ws://localhost:* https://*.mysite.com">
</head>
<body>
<script src="https://localhost:3333/remote-server/auth.js"></script>
</body>
</html>
仍会导致:
Refused to load the script 'https://localhost:3333/remote-server/auth.js' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".
它仍然没有参考<meta>
标签的内容
更新2
页面通过加载
chrome.windows.create({
url: 'chrome-extension://my-extension/auth.html',
type: 'popup',
height: 680,
width: 500
}, (windw) => console.log(windw))
HTTP头将优先,如果您有这些,元标记将被忽略。
问题是,谷歌chrome符合主要的网页标题。并且这些将优先,你必须为你试图加载脚本的页面禁用CSP。
相关文章:
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- chrome扩展更改主机/域警告
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 从选项页面更新chrome扩展清单权限
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- Chrome扩展:遍历不同的页面并收集数据
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 可以从Chrome扩展修改窗口对象吗
- 从popup.js|Chrome扩展访问DOM
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 在Chrome扩展内部输出Google API调用
- 检查是否存在使用chrome扩展的javascript库
- 从Chrome扩展访问Google Cloud SQL数据库
- Chrome扩展,Chrome.tabs.query的结果未定义
- 为tweet构建chrome扩展
- 在chrome扩展中使用AJAX获取目录中的文件数