Files
java-ai-agents/mcp-apps/harness/sandbox.html
T

26 lines
1.0 KiB
HTML

<!DOCTYPE html>
<meta charset="utf-8">
<title>sandbox proxy</title>
<style>html,body,iframe{margin:0;border:0;width:100%;height:100%}</style>
<body>
<script>
// The proxy of the spec: a second origin between the host and the view. It loads the HTML and relays messages.
const inner = document.createElement("iframe");
inner.id = "view";
inner.setAttribute("sandbox", "allow-scripts allow-same-origin");
const HOST = "http://localhost:7001";
window.addEventListener("message", (event) => {
if (event.source === window.parent && event.origin === HOST) {
if (event.data.method === "ui/notifications/sandbox-resource-ready") {
inner.srcdoc = event.data.params.html; // srcdoc inherits this page's CSP header
document.body.append(inner);
} else {
inner.contentWindow?.postMessage(event.data, "*");
}
} else if (event.source === inner.contentWindow) {
window.parent.postMessage(event.data, HOST);
}
});
window.parent.postMessage({ jsonrpc: "2.0", method: "ui/notifications/sandbox-proxy-ready", params: {} }, HOST);
</script>