Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
// An isolated iframe navigates a sibling that another process hosts to a response whose policy forbids framing.
// The sibling's process reports the violation without the source's settings object, and the response does not
// load as a document.
promiseTest(async () => {
const httpServer = httpTestServer();
const runId = uniqueID();
const targetHostname = uniqueLocalhostHostname("frame-ancestors-target");
const echo = async (path, headers, body, hostname) => {
const url = new URL(
await httpServer.createEcho("GET", path, {
status: 200,
headers: { "Content-Type": "text/html", ...headers },
body,
})
);
url.hostname = hostname;
return url;
};
const targetFirstUrl = await echo(`/frame-ancestors-target-first-${runId}`, {}, "<!DOCTYPE html>first", targetHostname);
const forbiddenUrl = await echo(
`/frame-ancestors-forbidden-${runId}`,
{ "Content-Security-Policy": "frame-ancestors 'none'" },
`<!DOCTYPE html><script>top.postMessage("the framed response loaded as a document", "*");<\/script>`,
targetHostname
);
const sourceUrl = await echo(
`/frame-ancestors-source-${runId}`,
{},
`<!DOCTYPE html><a id="link" target="target" href="${forbiddenUrl.href}">link</a>
<script>document.getElementById("link").click();<\/script>`,
uniqueLocalhostHostname("frame-ancestors-source")
);
const target = document.createElement("iframe");
target.name = "target";
target.src = targetFirstUrl;
document.body.appendChild(target);
await new Promise(resolve => (target.onload = resolve));
const messages = [];
addEventListener("message", event => messages.push(event.data));
const navigated = new Promise(resolve => target.addEventListener("load", resolve, { once: true }));
const source = document.createElement("iframe");
source.src = sourceUrl;
document.body.appendChild(source);
await navigated;
await timeout(0);
println(`messages: ${messages.length ? messages.join(", ") : "none"}`);
println(internals.dumpSiteIsolationProcessTree().trimEnd());
});
</script>