Truly independent web browser
LibWeb: Abandon a navigation fetch whose navigable lost its document
Andreas Kling364b58bcacd9
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 983540fc031..4457a8b5085 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -2372,6 +2372,16 @@ static void perform_navigation_params_fetch(JS::Realm& realm, GC::Ref<Navigation}}+ // AD-HOC: The navigable can be destroyed while the response is on its way, e.g. a popup closed right after it+ // was opened, with nothing to navigate left.+ if (state_holder->navigable->has_been_destroyed() || !state_holder->navigable->active_document()) {+ state_holder->fetch_controller->abort(realm, {});+ auto result = realm.heap().allocate<InternalNavigationResult>();+ result->navigation_params = LocalNavigable::NullOrError {};+ top_level_completion_steps->function()(*result);+ return;+ }+// 8. If request's body is null, then set entry's document state's resource to null.if (state_holder->request->body().has<Empty>()) {state_holder->resource_cleared = true;diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/popup-closed-before-its-first-response.txt b/Tests/LibWeb/Text/expected/SiteIsolation/popup-closed-before-its-first-response.txtnew file mode 100644index 00000000000..0a7d10a0d28--- /dev/null+++ b/Tests/LibWeb/Text/expected/SiteIsolation/popup-closed-before-its-first-response.txt@@ -0,0 +1,2 @@+popup.closed: true+opener surviveddiff --git a/Tests/LibWeb/Text/input/SiteIsolation/popup-closed-before-its-first-response.html b/Tests/LibWeb/Text/input/SiteIsolation/popup-closed-before-its-first-response.htmlnew file mode 100644index 00000000000..0336d0f28a6--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/popup-closed-before-its-first-response.html@@ -0,0 +1,26 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<script>+ // A popup closed right after it was opened has no document left by the time the response to its first navigation+ // arrives.+ promiseTest(async () => {+ const httpServer = httpTestServer();+ const url = new URL(+ await httpServer.createEcho("GET", "/popup-closed-before-its-first-response", {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: "<!DOCTYPE html>popup",+ })+ );+ url.hostname = uniqueLocalhostHostname("popup-closed-before-its-first-response");++ const popup = window.open(url.href, "popup");+ popup.close();+ println(`popup.closed: ${popup.closed}`);++ // The response has arrived once a fetch of the same URL completes.+ await fetch(url.href, { mode: "no-cors" });+ await timeout(100);+ println("opener survived");+ });+</script>