最近谷歌已經推出沙盒來增強其安全模式。他們recommend使用postMessage作爲與沙盒窗口進行通信的方式。但發佈的消息,我需要從後臺頁面發送的第一條消息:如何與Chrome打包應用程序中的沙盒窗口進行通信?
// 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
我已經提交了bug report,但不能等待好幾個月有人讀它之前,我需要在一個月內使用該應用程序。我該如何解決這個問題?我可以看到examples使用沙盒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>
你明白了嗎?你在哪裏實際發出postMessage請求。我沒有看到你的代碼。考慮通過這個[edit]鏈接添加。另外,請發佈您的清單文件。祝你好運! – jmort253
Manifest文件位於[示例](https://github.com/losomo/sandbox_test)中。 postMessage應該用'console.log(myWin);'來代替,只是這樣表示代碼是不可訪問的。 – hlidka