Skip to content

Truly independent web browser

1.6 KB
Raw Blame
<!DOCTYPE html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<style>
    @keyframes move {
        from { transform: translateX(0); }
        to { transform: translateX(100px); }
    }

    #animated {
        width: 20px;
        height: 20px;
        animation: move 10s linear infinite;
    }
</style>
<div id="animated"><div id="descendant"></div></div>
<div id="unrelated"></div>
<script>
    function printCompositorAnimations(title) {
        println(title);
        for (const line of internals.dumpCompositorAnimations().split("\n").filter(Boolean))
            println(`  ${line}`);
    }

    function sampledElements() {
        const events = parseStyleTrace(internals.takeStyleTrace()).filter(event => event.outcome?.startsWith("sampled"));
        return `[${[...new Set(events.map(event => event.element))].join(", ")}]`;
    }

    asyncTest(async done => {
        internals.updateStyle();
        for (let i = 0; i < 4; ++i)
            await new Promise(requestAnimationFrame);
        printCompositorAnimations("compositor animations:");

        internals.beginStyleTrace();
        const unrelatedObserver = new IntersectionObserver(() => {});
        unrelatedObserver.observe(unrelated);
        await new Promise(requestAnimationFrame);
        println(`unrelated observation samples: ${sampledElements()}`);

        internals.beginStyleTrace();
        const descendantObserver = new IntersectionObserver(() => {});
        descendantObserver.observe(descendant);
        await new Promise(requestAnimationFrame);
        println(`descendant observation samples: ${sampledElements()}`);
        done();
    });
</script>