Send the page-closed signal as a keepalive fetch, since WebKit's beacon carries Origin: null

AI Assisted
This commit is contained in:
Seth committed 2026-12-05 00:10:44 -08:00
1 parent 603c871720
commit 4ced32be5c
2 files changed
+16 -1

No files matched your search

+12
View File
@@ -112,3 +112,15 @@ test("anything but exactly one allowed origin keeps frame-ancestors 'none'", asy
assert.match(csp, /frame-ancestors 'none'$/, `${JSON.stringify(origin)}: ${csp}`);
}
});
test("the page-closed signal is a keepalive fetch, which carries the page's origin, not a beacon", () => {
// A body-less sendBeacon is a no-cors POST: under the console's
// `referrer-policy: no-referrer` it goes out with `Origin: null`, which /bye's
// origin check refuses (WebKit showed it; the Fetch standard says every engine
// does the same). A keepalive fetch is a cors request and sends the real origin.
const core = fs.readFileSync(path.join(ROOT, "src", "web-console", "public", "screens", "core.js"), "utf8");
const wire = core.slice(core.indexOf("export function wireChrome()"));
const pagehide = wire.slice(0, wire.indexOf("});"));
assert.match(pagehide, /fetch\("\/bye", \{ method: "POST", keepalive: true \}\)/, pagehide);
assert.doesNotMatch(core, /navigator\.sendBeacon\(/, "no beacon call left anywhere in the page's core");
});