Skip to content

Truly independent web browser

1.3 KB
Raw Blame
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
    asyncTest(async done => {
        const iframe = document.createElement("iframe");
        const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
        document.body.appendChild(iframe);
        await loaded;

        const sheet = new CSSStyleSheet();
        sheet.replaceSync(".target { color: rgb(1, 2, 3); }");
        const hosts = [document.createElement("div"), document.createElement("div")];
        for (const host of hosts) {
            const root = host.attachShadow({ mode: "open" });
            root.adoptedStyleSheets = [sheet];
            root.innerHTML = '<span class="target">target</span>';
            document.body.appendChild(host);
        }
        internals.updateStyle();

        const child = iframe.contentWindow;
        child.document.body.appendChild(child.document.adoptNode(hosts[0]));
        child.internals.updateStyle();

        sheet.replaceSync(".target { color: rgb(4, 5, 6); }");
        internals.updateStyle();
        child.internals.updateStyle();
        println(`old document: ${getComputedStyle(hosts[1].shadowRoot.firstElementChild).color}`);
        println(`new document: ${child.getComputedStyle(hosts[0].shadowRoot.firstElementChild).color}`);
        done();
    });
</script>