Skip to content

Truly independent web browser

1.1 KB
Raw Blame
<!DOCTYPE html>
<script src="./include.js"></script>
<script>
    promiseTest(async () => {
        // The srcdoc iframe inherits its base URL from its parent document. We need it to be localhost so that the
        // content blocker's matching rule will apply to it.
        const base = document.createElement("base");
        base.href = "http://localhost/";
        document.head.appendChild(base);

        try {
            const iframe = document.createElement("iframe");
            const loaded = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
            iframe.srcdoc = `<div class="ad"></div>`;
            document.body.appendChild(iframe);
            await loaded;

            const target = iframe.contentDocument.querySelector(".ad");

            println(getComputedStyle(target).display);

            internals.setContentBlockers("localhost##.ad");
            println(getComputedStyle(target).display);

            internals.setContentBlockers("");
            println(getComputedStyle(target).display);
        } finally {
            internals.setContentBlockers("");
        }
    });
</script>