Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<body>
<script>
// Adopting a media element with an in-flight fetch into a document that is not fully active
// must stop the fetch, so that adopting it back into a fully active document can resume it.
// Without that, the resume path would find a live fetch controller and crash.
asyncTest(async done => {
internals.setTestTimeout(15000);
const httpServer = httpTestServer();
const testID = crypto.randomUUID();
const token = `media-adoption-round-trip-${testID}`;
const mediaURL = new URL(await httpServer.createEcho("GET", `/media-adoption-round-trip-${testID}`, {
status: 200,
headers: { "Content-Type": "video/webm", "Cache-Control": "no-store" },
body: "",
wait_for_unblock: token,
}));
mediaURL.hostname = uniqueLocalhostHostname("media-adoption");
const unblockURL = new URL(`/unblock/${token}`, mediaURL);
unblockURL.hostname = uniqueLocalhostHostname("media-adoption-unblock");
const video = document.createElement("video");
video.preload = "auto";
video.src = mediaURL;
document.body.appendChild(video);
await new Promise(resolve => video.addEventListener("loadstart", resolve, { once: true }));
while (!internals.mediaElementIsFetching(video))
await new Promise(resolve => setTimeout(resolve, 0));
const inactiveDocument = new DOMParser().parseFromString("<body></body>", "text/html");
inactiveDocument.adoptNode(video);
document.body.appendChild(video);
println("video survived adoption round-trip during fetch");
video.addEventListener("error", () => {
println(`video error event (error=${video.error.code})`);
done();
});
await fetch(unblockURL);
});
</script>