Skip to content

Truly independent web browser

2.8 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
    // Assigning parent.location in an isolated frame whose parent is hosted by another process navigates that parent:
    // the Location stands for the remote navigable, and the navigate request crosses to its process via the UI process.
    promiseTest(async () => {
        const httpServer = httpTestServer();
        const childHostname = uniqueLocalhostHostname("oop-parent-location-child");
        const grandchildHostname = uniqueLocalhostHostname("oop-parent-location-grandchild");

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

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

        const grandchildUrl = new URL(
            await httpServer.createEcho("GET", "/oop-parent-location-grandchild", {
                status: 200,
                headers: { "Content-Type": "text/html" },
                body: `<!DOCTYPE html><script>parent.location = ${JSON.stringify(secondChildUrl.href)};<\/script>`,
            })
        );
        grandchildUrl.hostname = grandchildHostname;

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

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

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