Skip to content

Truly independent web browser

2.3 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
    // Sandboxed documents loaded over HTTP(S) share one process per origin of their URLs, whichever way a redirect took
    // them there. That process hosts only sandboxed documents, so it is not the process of the origin's other documents.
    promiseTest(async () => {
        const httpServer = httpTestServer();

        const childUrl = new URL(
            await httpServer.createEcho("GET", "/sandboxed-child", {
                status: 200,
                headers: { "Content-Type": "text/html" },
                body: "<!DOCTYPE html>child",
            })
        );

        const site = uniqueLocalhostHostname("sandboxed-site");
        const urlOnHost = (url, hostname) => {
            const result = new URL(url);
            result.hostname = hostname;
            return result;
        };

        const sameSiteRedirect = new URL(
            await httpServer.createEcho("GET", "/sandboxed-same-site-redirect", {
                status: 302,
                headers: { Location: childUrl.pathname },
            })
        );
        const crossSiteRedirect = new URL(
            await httpServer.createEcho("GET", "/sandboxed-cross-site-redirect", {
                status: 302,
                headers: { Location: urlOnHost(childUrl, `a.${site}`).href },
            })
        );

        const loadIframe = async (url, sandbox) => {
            const iframe = document.createElement("iframe");
            if (sandbox !== null) iframe.sandbox = sandbox;
            iframe.src = url;
            const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
            document.body.appendChild(iframe);
            await loaded;
        };

        await loadIframe(urlOnHost(childUrl, `a.${site}`), "");
        await loadIframe(urlOnHost(sameSiteRedirect, `a.${site}`), "");
        await loadIframe(urlOnHost(crossSiteRedirect, uniqueLocalhostHostname("redirecting-site")), "");
        await loadIframe(urlOnHost(childUrl, `b.${site}`), "");
        await loadIframe(urlOnHost(childUrl, uniqueLocalhostHostname("other-sandboxed-site")), "");
        await loadIframe(urlOnHost(childUrl, `a.${site}`), null);

        println(internals.dumpSiteIsolationProcessTree().trimEnd());
    });
</script>