Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
promiseTest(async () => {
internals.setTestTimeout(15000);
const httpServer = httpTestServer();
async function verifyReplacementLoadsBeforeDiscardedScript(kind, attributes) {
const token = `document-open-discards-${kind}-script`;
const scriptURL = await httpServer.createEcho("GET", `/${token}.js`, {
status: 200,
headers: {
"Content-Type": "text/javascript",
"Cache-Control": "no-store",
},
body: "parent.discardedScriptRan = true;",
wait_for_unblock: token,
});
const iframe = document.createElement("iframe");
const initialLoad = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
document.body.appendChild(iframe);
await initialLoad;
window.discardedScriptRan = false;
const iframeDocument = iframe.contentDocument;
iframeDocument.open().write(`<script ${attributes} src="${scriptURL}"><\/script><body>Discarded</body>`);
if (kind === "deferred")
iframeDocument.close();
const replacementLoad = new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));
iframeDocument.open().write("<body>Replacement</body>");
iframeDocument.close();
await replacementLoad;
println(`Replacement loaded before discarded ${kind} script response`);
println(`Discarded ${kind} script ran: ${discardedScriptRan}`);
await fetch(new URL(`/unblock/${token}`, scriptURL));
iframe.remove();
}
await verifyReplacementLoadsBeforeDiscardedScript("parsing-blocking", "");
await verifyReplacementLoadsBeforeDiscardedScript("deferred", "defer");
});
</script>