Skip to content

Truly independent web browser

2.0 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<style>
    body {
        margin: 0;
    }
    #spacer {
        height: 3000px;
    }
    iframe {
        display: block;
        width: 200px;
        height: 100px;
        border: 0;
    }
</style>
<div id="spacer"></div>
<script>
    // A lazy iframe below the fold loads as soon as its loading attribute goes to the Eager state, and has nothing left
    // to load once it's scrolled into view — even after a later navigation hands its document to another process.
    promiseTest(async () => {
        const httpServer = httpTestServer();
        const crossSiteUrl = async name => {
            const url = new URL(
                await httpServer.createEcho("GET", `/oop-lazy-iframe-made-eager-${name}`, {
                    status: 200,
                    headers: { "Content-Type": "text/html" },
                    body: `<!DOCTYPE html>${name}`,
                })
            );
            url.hostname = uniqueLocalhostHostname(`oop-lazy-iframe-made-eager-${name}`);
            return url;
        };
        const firstUrl = await crossSiteUrl("first");
        const secondUrl = await crossSiteUrl("second");

        const iframe = document.createElement("iframe");
        const nextLoad = () => new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
        iframe.loading = "lazy";
        iframe.src = firstUrl;
        document.getElementById("spacer").after(iframe);

        let loaded = nextLoad();
        iframe.loading = "eager";
        await loaded;
        println("loaded after loading=eager");

        loaded = nextLoad();
        iframe.src = secondUrl;
        await loaded;
        println("loaded after src change");

        window.scrollTo(0, iframe.getBoundingClientRect().top + scrollY);
        for (let i = 0; i < 5; ++i)
            await animationFrame();
        println(`frames after scrolling into view: ${window.length}`);
        println(internals.dumpSiteIsolationProcessTree().trimEnd());
    });
</script>