Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
function animationFrame() {
return new Promise(resolve => requestAnimationFrame(resolve));
}
asyncTest(async done => {
const iframe = document.createElement("iframe");
iframe.style.width = "300px";
iframe.style.height = "200px";
iframe.style.border = "0";
const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
iframe.srcdoc = `
<!DOCTYPE html>
<style>
@media (max-width: 400px) {
.target { color: rgb(1, 2, 3); }
}
</style>
<div class="target">target</div>
`;
document.body.appendChild(iframe);
await loaded;
const child = iframe.contentWindow;
const sheet = child.document.styleSheets[0];
const target = child.document.querySelector(".target");
child.internals.updateStyle();
println(`before disable: ${child.getComputedStyle(target).color}`);
sheet.disabled = true;
iframe.style.width = "500px";
document.body.offsetWidth;
await animationFrame();
child.document.body.offsetWidth;
sheet.disabled = false;
child.internals.updateStyle();
println(`after enable: ${child.getComputedStyle(target).color}`);
done();
});
</script>