Iframe Sandbox
Don't assume this is a perfect sandbox. Infinite loops will crash the main page. See this thread.
usage
var IframeSandbox =
config
All config options are passed to iframe
.
See here for iframe
config options.
var opts = container: documentbody src: urlOfBootstrappedIframe
Bootstrapped iframe
To use a hosted, bootstrapped iframe, specify the url as the src
config option.
See here for more about using a bootstrapped iframe.
methods
eval
Evals js in the sandbox's context. Calls the callback with the error (as a string) or the result.
sandbox
createWriteStream
Creates a WriteStream that writes to the document via document.write
.
Note: scripts written to the DOM wont be run until 'document.close()' is called,
triggered by the end of the stream.
var ws = sandboxsomewhereAwesome
'message' event
Inside the sandbox context there is an extra exposed global sandboxMessage
that will re-materialize objects in the main context and handle cross-context callbacks via dnode.
Listen to the 'message' event in the main context to receive the messages
sandbox sandbox
notes
Writing external script tags to the document does not seem to work.
The following will not load bundle.js
.
var ws = sandboxwsws