Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<style id="sheet">
#target { color: blue }
@media (width < 1px) {
#guard .activation-target { color: red }
}
</style>
<div id="guard"><span id="target" class="activation-target"></span></div>
<span class="activation-target"></span>
<script>
test(() => {
const sheet = document.getElementById("sheet").sheet;
// The first CSSOM edit recompiles shared contents into a private stylesheet. Insert and remove
// a dummy rule first, so the edits below are incremental.
sheet.insertRule(":not(*) {}", 0);
sheet.deleteRule(0);
const target = document.getElementById("target");
const group = document.getElementById("sheet").sheet.cssRules[1];
internals.updateStyle();
group.media.mediaText = "all";
internals.updateStyle();
println(`active color: ${getComputedStyle(target).color}`);
group.media.mediaText = "(width < 1px)";
internals.updateStyle();
println(`inactive color: ${getComputedStyle(target).color}`);
});
</script>