Google chrome 为什么chrome扩展沙盒页面块加载外部脚本
我想在一个沙盒页面中加载一些外部脚本,然后在事件页面上使用消息传递和沙盒页面通信以使用这些脚本。我基本上遵循这两个文件: 这是我在沙盒和事件页面配置中使用的manifest.json:Google chrome 为什么chrome扩展沙盒页面块加载外部脚本,google-chrome,google-chrome-extension,content-security-policy,Google Chrome,Google Chrome Extension,Content Security Policy,我想在一个沙盒页面中加载一些外部脚本,然后在事件页面上使用消息传递和沙盒页面通信以使用这些脚本。我基本上遵循这两个文件: 这是我在沙盒和事件页面配置中使用的manifest.json: { "manifest_version": 2, "name": "Diver", "description": "Diver", "version": "0.0.1", "devtools_page": "devtools.html", "minimum_ch
{
"manifest_version": 2,
"name": "Diver",
"description": "Diver",
"version": "0.0.1",
"devtools_page": "devtools.html",
"minimum_chrome_version" : "57",
"background": {
"page": "eventpage.html",
"persistent": false
},
"sandbox": {
"pages": ["sandbox.html"]
}
}
这是eventpage.html,它在iframe中加载sandbox.html:
<!doctype html>
<html>
<body>
<iframe id="sandboxFrame" src="sandbox.html"></iframe>
</body>
</html>
这是sandbox.html,它加载一个外部脚本:
<!doctype html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ajv/5.2.3/ajv.min.js"></script>
</head>
<body>
</body>
</html>
当我尝试它时,我得到一个错误,说加载外部脚本被内容安全策略阻止。根据文件,这是不允许的:
从版本57开始,Chrome将不再允许沙盒页面中包含外部web内容(包括嵌入的框架和脚本)。请改用webview
此外,您指定的CSP可能不允许在沙盒页面中加载外部web内容
文档要求我使用webview,但webview仅在Chrome应用程序中可用。接下来,我将sandbox.html上载到cdn中,并将其替换到eventpage.html中:
<!doctype html>
<html>
<body>
<iframe id="sandboxFrame" src="https://www.somecdn.com/sandbox.html"></iframe>
</body>
</html>
这次加载外部脚本,可能是因为该外部页面没有CSP阻止脚本
我不明白为什么在扩展中的sandbox.html中使用相同的脚本时会被阻止,而在从外部域加载sandbox.html时却不会。我知道这是因为CSP,但为什么Chrome决定用这种方式阻止它呢。我在Chrome56上测试了它,它没有被阻塞。只有在Chrome 57被屏蔽之后。读了你的问题后,我真的看不清你在问什么。@Xan抱歉,这个问题让人困惑。我添加了代码示例并编辑了问题。请再看一看。谢谢。不,不,我理解你的情况(尽管代码是受欢迎的)。但是你在寻找什么样的答案呢?你的问题是什么?“为什么chrome extension sandbox page阻止加载外部脚本?”我只是想确认我的发现是正确的,并理解在sandbox page中阻止外部脚本的更改背后的安全问题。好的,那么你问的是“为什么会更改”。那我就得找到那辆车。。