Do something like this:
manifest.json
"sandbox": { "pages": ["my_ui.html"] }
my_ui.html
<script type="text/javascript" src="knockout-1.2.3.4.js"></script> <script type="text/javascript" src="my_ui.js"></script>
my_ui.js
this.onSomethingChange = function() { window.top.postMessage( { command: 'please-do-something', myArgument: this.myArgument() }, '*'); };
container.html
<script type="text/javascript" src="container.js"></script> <iframe id="knockoutFrame" src="my_ui.html"></iframe>
container.js
window.addEventListener('message', function(event) { var kocw = document.getElementById('knockoutFrame').contentWindow; var anotherContentWindow =
Your expression, βI have to define the actual application.html as a sandbox page and include it as an iframe in a dummy containerβ, is probably not what you wanted. The idea is that the sandbox is the smallest thing possible, a message on the gatekeeper page that checks the messages, and forces the gatekeeper to forward narrow messages to your non-isolated application logic. If you just put everything in the sandbox, you defeat the goal of the sandbox.
Disclaimer: I have not carefully studied this code in terms of security. You want to assume that hostile messages come from the sandbox (or from other sources, for that matter), and are doing everything you can to eliminate this threat.
source share