Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<style>
iframe {
display: block;
width: 200px;
height: 100px;
border: 0;
}
</style>
<script>
// A top-level document that a response sandboxes holds another site's content, so it does not stay in the process
// of the document that navigated to it.
promiseTest(async () => {
const httpServer = httpTestServer();
const popupUrl = new URL(
await httpServer.createEcho("GET", "/csp-sandboxed-popup", {
status: 200,
headers: { "Content-Type": "text/html", "Content-Security-Policy": "sandbox allow-scripts" },
body: `<!DOCTYPE html><script>
opener.postMessage({ origin: self.origin, processId: internals.webContentProcessId() }, "*");
<\/script>`,
})
);
popupUrl.hostname = uniqueLocalhostHostname("csp-sandboxed-popup");
const iframeUrl = new URL(
await httpServer.createEcho("GET", "/csp-sandboxed-popup-opener", {
status: 200,
headers: { "Content-Type": "text/html" },
body: `<!DOCTYPE html><script>
addEventListener("mousedown", () => {
window.popup = window.open(${JSON.stringify(popupUrl.href)}, "csp-sandboxed-popup");
});
addEventListener("message", event => {
parent.postMessage({
popupIsSandboxed: event.data.origin === "null",
popupIsInProcessOfInitiator: event.data.processId === internals.webContentProcessId(),
}, "*");
window.popup.close();
});
parent.postMessage("ready", "*");
<\/script>`,
})
);
iframeUrl.hostname = uniqueLocalhostHostname("csp-sandboxed-popup-opener");
const nextMessage = () => new Promise(resolve => addEventListener("message", event => resolve(event.data), { once: true }));
const ready = nextMessage();
const iframe = document.createElement("iframe");
iframe.src = iframeUrl;
document.body.appendChild(iframe);
await ready;
const report = nextMessage();
const rect = iframe.getBoundingClientRect();
internals.clickThroughUIProcess(rect.left + 30, rect.top + 20);
println(JSON.stringify(await report));
});
</script>