Skip to content

Truly independent web browser

1.4 KB
Raw Blame
<!DOCTYPE html>
<iframe style="height: 50px; width: 100px" srcdoc='<!DOCTYPE html>
<style>
    @property --ratio { syntax: "<number>"; inherits: true; initial-value: 1; }
    #parent { --ratio: calc(100vw / 160px); }
    #child { opacity: var(--ratio); }
</style>
<div id="parent"><div id="child"></div></div>
'></iframe>
<script src="../include.js"></script>
<script>
    asyncTest(async done => {
        // NB: The iframe's document replaces the initial one as its contents load.
        if (document.readyState !== "complete")
            await new Promise(resolve => window.addEventListener("load", resolve));
        const iframe = document.querySelector("iframe");
        const contentWindow = iframe.contentWindow;
        const contentDocument = iframe.contentDocument;
        const nextFrames = async () => {
            await new Promise(resolve => contentWindow.requestAnimationFrame(resolve));
            await new Promise(resolve => contentWindow.requestAnimationFrame(resolve));
        };
        const report = () => {
            const style = id => contentWindow.getComputedStyle(contentDocument.getElementById(id));
            println(`Width ${contentWindow.innerWidth}: parent --ratio ${style("parent").getPropertyValue("--ratio")}, child opacity ${style("child").opacity}`);
        };
        await nextFrames();
        report();
        iframe.style.width = "160px";
        await nextFrames();
        report();
        done();
    });
</script>