2 function with_iframe(url
) {
3 return new Promise(function(resolve
) {
4 var frame
= document
.createElement('iframe');
6 frame
.onload = function() { resolve(frame
); };
7 document
.body
.appendChild(frame
);
11 function with_sandboxed_iframe(url
, sandbox
) {
12 return new Promise(function(resolve
) {
13 var frame
= document
.createElement('iframe');
14 frame
.sandbox
= sandbox
;
16 frame
.onload = function() { resolve(frame
); };
17 document
.body
.appendChild(frame
);
21 window
.onmessage = function (e
) {
22 var id
= e
.data
['id'];
23 fetch(location
.href
+ "_fetch", {mode
: 'no-cors'})
25 return with_iframe(location
.href
+ "_iframe");
28 return with_sandboxed_iframe(location
.href
+ "_script",
32 return with_sandboxed_iframe(location
.href
+ "_script-origin",
33 "allow-scripts allow-same-origin");
36 window
.top
.postMessage({id
: id
, result
: 'done'}, '*');
39 window
.top
.postMessage({id
: id
, result
: 'error: ' + e
.toString()}, '*');