最近谷歌引入了沙盒来增强其安全模型。他们建议使用postMessage作为与沙盒窗口通信的方式。但是要发布消息,我需要从后台页面发送第一条消息:
// in background page:
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('index.html', { // index.html is sandboxed
'width': 800,
'height': 500
}, function(myWin) {
// myWin is ready, I want to post a message
console.log(myWin); // This is never called after version 23.0.1246, an error is thrown
});
});
这在版本中运行良好,23.0.1246
但在下一次更新中停止工作,并且从未返回。现在,这种技术在 dev 和 beta 中都会引发错误(在 和 上测试过24.0.1284
)23.0.1271.17
。
我准备了一个显示错误的最小 Chrome 打包应用程序(在启动应用程序后的后台页面控制台中):https ://github.com/losomo/sandbox_test
我已经提交了一个错误报告,但不能再等几个月才能有人阅读它,我需要在一个月内使用该应用程序。我该如何解决这个问题?我可以看到使用沙盒iframe的示例仍然有效。有没有办法在不使用 iframe 的情况下使用沙盒并且仍然能够与页面通信?
这是清单:
{
"name": "Sandbox test",
"description": "Sandbox test",
"manifest_version": 2,
"minimum_chrome_version": "23",
"version": "0.0.1",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"sandbox": {
"pages": ["index.html"]
},
"permissions": [
"app.window"
]
}
和 index.html 页面:
<!doctype html>
<html lang="cs">
<head>
<meta charset="UTF-8">
</head>
<body>
Hi
</body>
</html>