Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
// A link the user opens in a new tab — with a middle-click, or a click with the platform's Ctrl key held — is
// still navigated to from this page, so it's site-controlled and carries this page's referrer as following it
// would, rather than going out as a URL the user agent supplied.
asyncTest(async done => {
const server = httpTestServer();
const platformCtrl = /mac/i.test(navigator.platform) ? internals.MOD_SUPER : internals.MOD_CTRL;
async function recorded(echoURL) {
const url = server.recordedRequestHeadersURL(echoURL);
for (let attempt = 0; attempt < 600; ++attempt) {
try {
const response = await fetch(url);
if (response.ok)
return await response.json();
} catch {}
await timeout(25);
}
return null;
}
async function open(name, button, modifiers, rel) {
const url = await server.createEcho("GET", `/sec-fetch-site-new-tab-${name}`, {
status: 200,
headers: { "Content-Type": "text/html" },
body: "<!DOCTYPE html>",
});
const link = document.createElement("a");
link.href = url;
link.textContent = name;
link.style.display = "block";
if (rel)
link.rel = rel;
document.body.append(link);
const rect = link.getBoundingClientRect();
internals.click(rect.x + rect.width / 2, rect.y + rect.height / 2, 1, button, modifiers);
const headers = await recorded(url);
const referer = headers?.["Referer"]?.[0];
println(`${name}: Sec-Fetch-Site ${headers?.["Sec-Fetch-Site"]?.[0]}, Sec-Fetch-User ${headers?.["Sec-Fetch-User"]?.[0]}, Referer ${referer === location.href ? "this page" : referer}`);
link.remove();
}
await open("middle-click", 1, internals.MOD_NONE);
await open("ctrl-click", 0, platformCtrl);
await open("ctrl-click-noreferrer", 0, platformCtrl, "noreferrer");
done();
});
</script>