Skip to content

Truly independent web browser

2.5 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
    // A parent navigating its out-of-process iframe to another page of the site the frame displays keeps the frame in
    // the process hosting that site: the new document's agent cluster is already hosted there. The navigation is
    // fetched by the parent's process, so the document must be handed to the frame's process to be created.
    promiseTest(async () => {
        const httpServer = httpTestServer();
        const childHostname = uniqueLocalhostHostname("oop-iframe-renavigate");

        const firstChildUrl = new URL(
            await httpServer.createEcho("GET", "/oop-iframe-renavigate-first", {
                status: 200,
                headers: { "Content-Type": "text/html" },
                body: "<!DOCTYPE html>first",
            })
        );
        firstChildUrl.hostname = childHostname;

        const markerUrl = new URL(
            await httpServer.createEcho("GET", "/oop-iframe-renavigate-marker", {
                status: 200,
                headers: { "Content-Type": "text/plain" },
                body: "marker",
            })
        );
        markerUrl.hostname = childHostname;

        const secondChildUrl = new URL(
            await httpServer.createEcho("GET", "/oop-iframe-renavigate-second", {
                status: 200,
                headers: { "Content-Type": "text/html" },
                body: `<!DOCTYPE html>second<script>fetch(${JSON.stringify(markerUrl.href)});<\/script>`,
            })
        );
        secondChildUrl.hostname = childHostname;

        const iframe = document.createElement("iframe");
        iframe.src = firstChildUrl;
        document.body.appendChild(iframe);
        if (!(await waitForCondition(() => internals.dumpSiteIsolationProcessTree().includes("remote")))) {
            println("iframe did not become remote");
            return;
        }

        iframe.src = secondChildUrl;

        // The second document's script fetches the marker; the echo server records the request when it is made.
        const recordedUrl = httpServer.recordedRequestHeadersURL(markerUrl);
        let secondDocumentRan = false;
        for (let attempt = 0; attempt < 600 && !secondDocumentRan; ++attempt) {
            try {
                secondDocumentRan = (await fetch(recordedUrl)).ok;
            } catch {}
            if (!secondDocumentRan) await timeout(25);
        }
        println(`second document ran: ${secondDocumentRan}`);
        println(internals.dumpSiteIsolationProcessTree().trimEnd());
    });
</script>