Skip to content

Truly independent web browser

2.0 KB
Raw Blame
<!doctype html>
<script src="../include.js"></script>
<script>
    asyncTest(async done => {
        const server = httpTestServer();
        const hostname = uniqueLocalhostHostname("audio-worklet-credentials");
        const moduleURL = new URL(
            await server.createEcho("GET", "/audio-worklet-credentials.js", {
                status: 200,
                headers: {
                    "Content-Type": "text/javascript",
                    "Cache-Control": "no-store",
                },
                body: "registerProcessor('processor', class extends AudioWorkletProcessor {});",
            })
        );
        moduleURL.hostname = hostname;

        const scriptStartTag = "<scr" + "ipt";
        const scriptEndTag = "</scr" + "ipt>";
        const pageURL = new URL(
            await server.createEcho("GET", "/audio-worklet-credentials.html", {
                status: 200,
                headers: {
                    "Content-Type": "text/html",
                    "Set-Cookie": "SID=secret; Path=/; HttpOnly; SameSite=Strict",
                },
                body: `<!DOCTYPE html>${scriptStartTag}>
                const context = new OfflineAudioContext(1, 128, 48000);
                context.audioWorklet.addModule(${JSON.stringify(moduleURL.href)}, { credentials: "omit" });
                ${scriptEndTag}`,
            })
        );
        pageURL.hostname = hostname;

        const frame = document.createElement("iframe");
        frame.src = `${pageURL.href}?private=capability`;
        document.body.appendChild(frame);

        const recordedURL = server.recordedRequestHeadersURL(moduleURL);
        let response;
        while (true) {
            try {
                response = await fetch(recordedURL);
                if (response.ok) break;
            } catch {}
        }

        const headers = await response.json();
        println(`${headers.Cookie ? "FAIL" : "PASS"}: AudioWorklet omitted cookie`);
        done();
    });
</script>