Skip to content

Truly independent web browser

1.7 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
    // A document with a fragment runs the focusing steps when it finishes parsing. In an isolated iframe, the top-level
    // traversable those steps are phrased on is hosted by another process.
    promiseTest(async () => {
        const httpServer = httpTestServer();

        const markerUrl = new URL(
            await httpServer.createEcho("GET", "/oop-fragment-marker", {
                status: 200,
                headers: { "Content-Type": "text/plain" },
                body: "marker",
            })
        );
        markerUrl.hostname = uniqueLocalhostHostname("oop-fragment-child");
        const childUrl = new URL(
            await httpServer.createEcho("GET", "/oop-fragment-child", {
                status: 200,
                headers: { "Content-Type": "text/html" },
                body: `<!DOCTYPE html><p id="target" tabindex="0">target</p><script>addEventListener("load", () => fetch(${JSON.stringify(markerUrl.href)}));<\/script>`,
            })
        );
        childUrl.hostname = markerUrl.hostname;
        childUrl.hash = "#target";

        const iframe = document.createElement("iframe");
        iframe.src = childUrl;
        document.body.appendChild(iframe);

        const recordedUrl = httpServer.recordedRequestHeadersURL(markerUrl);
        let loaded = false;
        for (let attempt = 0; attempt < 200 && !loaded; ++attempt) {
            try {
                loaded = (await fetch(recordedUrl)).ok;
            } catch {}
            if (!loaded) await timeout(25);
        }
        println(`child with a fragment finished loading: ${loaded}`);
        println(internals.dumpSiteIsolationProcessTree().trimEnd());
    });
</script>