【发布时间】:2012-07-07 01:59:27
【问题描述】:
Chrome 扩展的清单版本 2 将不再支持在常规扩展页面上使用 eval 或 new Function。我的 chrome 扩展在选项页面上使用了一个 UI 框架(Kendo UI),它利用了这些机制,因此我正在寻找解决方案。
根据 IO 2012 中的this session,想法是将相应页面放入沙箱并通过 iframe 将其加载到扩展程序中。
这是我正在尝试做的一个简化示例:https://gist.github.com/3058943
manifest.json:
{
"name": "Sandbox test",
"manifest_version": 2,
"options_page": "main.html",
"sandbox": {
"pages": [ "index.html" ]
}
}
main.html:
<html>
<head></head>
<body>
<iframe id="iframe" src="index.html" ></iframe>
</body>
</html>
index.html:
<html>
<head></head>
<body>
<h1>Inside the sandbox</h1>
</body>
</html>
当我在此示例中加载选项页面时,我收到了错误消息:
拒绝加载 chrome-extension://fahdnpkbgfjkocogbjlljfbhnljcehoh/index.html。资源必须列在 web_accessible_resources 清单键中才能被网页加载。
我不认为每个沙盒页面也应该是 web_accessible_resources。 但即使我尝试在清单文件中将沙盒页面也定义为 web_accessible_resources,沙盒页面也会被加载,但在 iframe 中使用 new Function 仍然会被阻止。
【问题讨论】:
-
开发通道版本 21.0.1180.15 中解决的问题