title: How to communicate with a sandboxed window in Chrome packaged App?
body: <p>Recently Google has introduced <strong>sandbox</strong> to enhance its security model. They <a href="http://developer.chrome.com/trunk/apps/sandboxingEval.html" rel="nofollow">recommend</a> using <strong>postMessage</strong> as the way to communicate with the sandboxed window. But to post a message I need to send the first message from the background page:</p>
  
  <pre><code>// 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
    });
  });
  </code></pre>
  
  <p>This worked fine in version <code>23.0.1246</code> but ceased to work with the next update and has never returned back. Now this technique throws errors in both dev and beta (tested on <code>24.0.1284</code> and <code>23.0.1271.17</code>).</p>
  
  <p>I have prepared a minimal Chrome packaged application that shows the error (in the background page console after launching the app): <a href="https://github.com/losomo/sandbox_test" rel="nofollow">https://github.com/losomo/sandbox_test</a></p>
  
  <p>I have submitted a <a href="http://code.google.com/p/chromium/issues/detail?id=147481" rel="nofollow">bug report</a> but can't wait many more months before someone reads it, I need to use the application within a month. How do I work around this issue? I can see that <a href="https://github.com/GoogleChrome/chrome-app-samples/tree/master/sandbox" rel="nofollow">examples</a> that use sandboxed <strong>iframe</strong> still work. Is there a way to use a sandbox without using iframes and still be able to communicate with the page?</p>
  
  <p>Here is the manifest:</p>
  
  <pre><code>{
    "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"
    ]
  }
  </code></pre>
  
  <p>And the index.html page:</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html lang="cs"&gt;
  &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
  &lt;/head&gt;
  &lt;body&gt;
      Hi
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>