Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
function nextTask() {
const { promise, resolve } = Promise.withResolvers();
const channel = new MessageChannel();
channel.port1.onmessage = resolve;
channel.port2.postMessage(null);
return promise;
}
asyncTest(async done => {
internals.setManualRenderingOpportunities(true);
await nextTask();
let callbackCount = 0;
requestAnimationFrame(() => {
++callbackCount;
requestAnimationFrame(() => ++callbackCount);
});
internals.injectRenderingOpportunity(performance.now());
await nextTask();
const afterFirstOpportunity = callbackCount;
await nextTask();
const afterAnotherTask = callbackCount;
internals.injectRenderingOpportunity(performance.now());
await nextTask();
internals.setManualRenderingOpportunities(false);
println(`callbacks after first opportunity: ${afterFirstOpportunity}`);
println(`callbacks after another task: ${afterAnotherTask}`);
println(`callbacks after second opportunity: ${callbackCount}`);
done();
});
</script>