Skip to content

Truly independent web browser

1.0 KB
Raw Blame
<!DOCTYPE html>
<script src="include.js"></script>
<script>
    asyncTest(async done => {
        const childSource = `<!DOCTYPE html><script>
            try {
                navigator.getGamepads();
                parent.postMessage("allowed", "*");
            } catch (e) {
                parent.postMessage(e.name, "*");
            }
        <\/script>`;

        const frame = async (name, allow) => {
            const iframe = document.createElement("iframe");
            if (allow !== undefined)
                iframe.setAttribute("allow", allow);
            iframe.srcdoc = childSource;
            const result = await new Promise(resolve => {
                addEventListener("message", event => resolve(event.data), { once: true });
                document.body.appendChild(iframe);
            });
            println(`${name}: ${result}`);
            iframe.remove();
        };

        await frame("without-allow");
        await frame("allow-none", "gamepad 'none'");

        done();
    });
</script>