-
Notifications
You must be signed in to change notification settings - Fork 0
/
outer-script.mjs
42 lines (35 loc) · 1.23 KB
/
outer-script.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const send = document.querySelector("#send");
const output = document.querySelector("#output");
const syncScript = document.querySelector("#sync-script");
const subframeSelector = document.querySelector("#subframe-selector");
send.onclick = async () => {
const module = await WebAssembly.compileStreaming(fetch("simple.wasm"));
frames[0].postMessage(module, "*");
};
syncScript.onclick = () => {
try {
frames[0].document.querySelector("#output").textContent += `Was able to script the iframe\n`;
} catch (e) {
output.textContent += `Failed to script the iframe: ${e.message}\n`;
}
};
if (subframeSelector) {
subframeSelector.onchange = () => {
replaceSubframe(subframeSelector.value);
location.hash = subframeSelector.value;
};
if (location.hash) {
const frameURL = location.hash.substring(1);
replaceSubframe(frameURL);
subframeSelector.value = frameURL;
} else {
subframeSelector.onchange();
}
}
function replaceSubframe(frameURL) {
const iframe = document.createElement("iframe");
iframe.src = frameURL;
document.querySelector("iframe").replaceWith(iframe);
}
output.textContent += `window.originAgentCluster: ${window.originAgentCluster}\n`;
document.domain = "origin-agent-cluster-demo.dev";