Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
// A popup in another process than its opener keeps the name it was opened with, and the opener reaches it by that name.
promiseTest(async () => {
const httpServer = httpTestServer();
const runId = crypto.randomUUID();
const nextMessage = () => new Promise(resolve => addEventListener("message", event => resolve(event.data), { once: true }));
// A popup's first navigation from this file keeps the opener's process, so it moves on to another site.
const crossSiteUrl = async (name, body) => {
const url = new URL(await httpServer.createEcho("GET", `/${name}-${runId}`, {
status: 200,
headers: { "Content-Type": "text/html" },
body: `<!DOCTYPE html><script>${body}<\/script>`,
}));
url.hostname = uniqueLocalhostHostname(name);
return url.href;
};
const popupUrlMovingTo = async (name, url) => httpServer.createEcho("GET", `/${name}-${runId}`, {
status: 200,
headers: { "Content-Type": "text/html" },
body: `<!DOCTYPE html><script>location.href = ${JSON.stringify(url)};<\/script>`,
});
const arrived = nextMessage();
const popup = window.open(await popupUrlMovingTo("name-first", await crossSiteUrl("name-cross-site", `opener.postMessage("arrived with name " + name, "*");`)), "named-popup");
println(await arrived);
const reopened = nextMessage();
const samePopup = window.open(await crossSiteUrl("name-reopened", `opener.postMessage("reopened with name " + name, "*");`), "named-popup");
println(await reopened);
println(`window.open() returned the same popup: ${samePopup === popup}`);
popup.close();
});
</script>