Truly independent web browser
<!DOCTYPE html>
<!-- A custom property on the root changes every few milliseconds while tasks remove the elements inheriting it, so
some are removed while a style update moving their environment is in flight. -->
<html class="test-wait">
<body>
<div id="root"></div>
<script>
const ELEMENT_COUNT = 2000;
const leaves = [];
for (let i = 0; i < ELEMENT_COUNT; ++i) {
const leaf = document.createElement("div");
root.append(leaf);
leaves.push(leaf);
}
const channel = new MessageChannel();
channel.port1.onmessage = () => {
const leaf = leaves.pop();
if (!leaf)
return;
leaf.remove();
channel.port2.postMessage(0);
};
channel.port2.postMessage(0);
const start = performance.now();
(function tick(n) {
document.documentElement.style.setProperty("--a", n + "px");
if (leaves.length && performance.now() - start < 3000)
setTimeout(tick, 4, n + 1);
else
document.documentElement.classList.remove("test-wait");
})(0);
</script>
</body>
</html>