Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<script src="../work-test.js"></script>
<style>
@keyframes pulse {
from { opacity: 0.2; }
to { opacity: 0.8; }
}
.infinite {
width: 10px;
height: 10px;
animation: pulse 10s linear infinite;
}
#finite {
width: 10px;
height: 10px;
animation: pulse 300ms linear forwards;
}
</style>
<div class="infinite"></div>
<div class="infinite"></div>
<div class="infinite"></div>
<div class="infinite"></div>
<div class="infinite"></div>
<div id="finite"></div>
<script>
function compositorAnimationDump() {
const lines = internals.dumpCompositorAnimations().split("\n").filter(Boolean);
const animations = lines.filter(line => /^(opacity|background-color|filter|transform) /.test(line)).sort();
return [...animations, ...lines.filter(line => !animations.includes(line))];
}
function printCompositorAnimations(title) {
println(title);
for (const line of compositorAnimationDump())
println(` ${line}`);
}
function samples() {
const events = parseStyleTrace(internals.takeStyleTrace()).filter(event => event.outcome?.startsWith("sampled"));
return `[${events.map(event => event.element).join(", ")}]`;
}
function frameRequests() {
return `[${internals.takeRenderingTrace().split("\n").filter(line => line.startsWith("animation frame pump request")).join(", ")}]`;
}
asyncTest(async done => {
// Hold the animation clock still while the compositor publishes the effects.
const timeline = internals.createInternalAnimationTimeline();
const animations = document.getAnimations();
for (const animation of animations) {
animation.timeline = timeline;
animation.startTime = 0;
}
timeline.setTime(0);
timeline.setTimeForObservation(0);
await new Promise(requestAnimationFrame);
await new Promise(requestAnimationFrame);
printCompositorAnimations("all effects use the compositor:");
let receivedAnimationEnd = false;
finite.addEventListener("animationend", () => receivedAnimationEnd = true, { once: true });
internals.beginStyleTrace();
internals.beginRenderingTrace();
timeline.setTimeForObservation(299);
internals.fireCompositorAnimationWakeupForTesting(299);
println(`early wake-up samples: ${samples()}, frame requests: ${frameRequests()}`);
internals.beginStyleTrace();
internals.beginRenderingTrace();
timeline.setTimeForObservation(301);
internals.fireCompositorAnimationWakeupForTesting(301);
timeline.setTime(301);
await new Promise(requestAnimationFrame);
println(`finite end samples: ${samples()}`);
println(`finite end frame requests: ${frameRequests()}`);
printCompositorAnimations("infinite effects remain on the compositor:");
println(`finite animation dispatches its end event: ${receivedAnimationEnd}`);
for (const animation of animations)
animation.cancel();
done();
});
</script>