Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
function animationFrame() {
return new Promise(resolve => requestAnimationFrame(resolve));
}
async function resizeIframe(iframe, child, width) {
iframe.style.width = `${width}px`;
document.body.offsetWidth;
await animationFrame();
child.document.body.offsetWidth;
child.internals.updateStyle();
}
promiseTest(async () => {
const iframe = document.createElement("iframe");
iframe.style.border = "0";
iframe.style.width = "300px";
iframe.style.height = "200px";
const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
iframe.srcdoc = `
<!DOCTYPE html>
<style>
html {
font-size: 10px;
}
@media (min-width: 400px) {
html {
font-size: 20px;
}
}
#target {
font-size: 10px;
left: 0;
position: relative;
}
</style>
<div id="target"></div>
<script>
const animation = document.getElementById("target").animate([{ left: "1rem" }, { left: "1rem" }], {
duration: 1000,
fill: "both",
});
animation.pause();
animation.currentTime = 500;
<\/script>
`;
document.body.appendChild(iframe);
await loaded;
const child = iframe.contentWindow;
const target = child.document.getElementById("target");
child.internals.updateStyle();
println(`initial animated left: ${child.getComputedStyle(target).left}`);
await resizeIframe(iframe, child, 500);
println(`resized animated left: ${child.getComputedStyle(target).left}`);
await resizeIframe(iframe, child, 300);
println(`resized back animated left: ${child.getComputedStyle(target).left}`);
});
</script>