Truly independent web browser
LibWeb: Navigate the relevant Document's navigable through Location
Jelle Raaijmakersecdd1e407348
diff --git a/Libraries/LibWeb/HTML/Location.cpp b/Libraries/LibWeb/HTML/Location.cppindex f7ba93d3918..89a86805534 100644--- a/Libraries/LibWeb/HTML/Location.cpp+++ b/Libraries/LibWeb/HTML/Location.cpp@@ -301,13 +301,21 @@ bool Location::has_relevant_document() constWebIDL::ExceptionOr<void> Location::navigate(URL::URL url, NavigationHistoryBehavior history_handling){// 1. Let navigable be location's relevant global object's navigable.- auto navigable = m_window.visit([](auto const& window) -> GC::Ptr<Navigable> { return window->navigable(); });+ // INTEROP: Other browsers keep a window reused from an initial about:blank with the about:blank until the new+ // document commits, so its Location navigates the about:blank's navigable. Take the relevant Document's.+ // FIXME: Associate a reused window with the new document when it is made active, not when it is created, which+ // leaves the window without a navigable meanwhile.+ auto navigable = m_window.visit(+ [&](GC::Ref<Window> const&) -> GC::Ptr<Navigable> { return relevant_document()->navigable(); },+ [](GC::Ref<RemoteWindow> const& window) -> GC::Ptr<Navigable> { return window->navigable(); });+ if (!navigable)+ return {};// 2. Let sourceDocument be the incumbent global object's associated Document.auto& source_document = incumbent_window().associated_document();// 3. If location's relevant Document is not yet completely loaded, and the incumbent global object does not have transient activation, then set historyHandling to "replace".- // NB: The relevant Document is navigable's active document, which step 1 reached through the relevant global object.+ // NB: The relevant Document is navigable's active document.if (!navigable->active_document_is_completely_loaded() && !incumbent_window().has_transient_activation()) {history_handling = NavigationHistoryBehavior::Replace;}diff --git a/Tests/LibWeb/Crash/HTML/location-href-setter-during-navigation-from-initial-about-blank.html b/Tests/LibWeb/Crash/HTML/location-href-setter-during-navigation-from-initial-about-blank.htmlnew file mode 100644index 00000000000..5c98ea0c769--- /dev/null+++ b/Tests/LibWeb/Crash/HTML/location-href-setter-during-navigation-from-initial-about-blank.html@@ -0,0 +1,57 @@+<!DOCTYPE html>+<html class="test-wait">+ <body>+ <script>+ const runId = crypto.randomUUID();++ async function createEcho(name, body) {+ const path = `/echo/${runId}/${name}`;+ await fetch("/echo", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ method: "GET",+ path,+ status: 200,+ headers: { "Content-Type": "text/html", "Cache-Control": "no-store" },+ body,+ }),+ });+ return path;+ }++ async function startStalledNavigation(frame, url) {+ const frameWindow = frame.contentWindow;+ frame.src = url;+ while (frameWindow.document.URL === "about:blank") await new Promise(resolve => setTimeout(resolve, 0));+ }++ (async () => {+ const stalled = await createEcho("stalled", "<!DOCTYPE html>" + "x".repeat(8192));+ const stalledAfterFirstChunk = `${stalled}?chunks=4096&chunk_delay_ms=3000`;+ const target = await createEcho("target", "<!DOCTYPE html>");++ const frame = document.createElement("iframe");+ document.body.append(frame);+ const frameLocation = frame.contentWindow.location;+ await startStalledNavigation(frame, stalledAfterFirstChunk);+ const frameLoaded = new Promise(resolve => frame.addEventListener("load", resolve, { once: true }));+ frameLocation.href = target;+ await frameLoaded;+ if (frame.contentDocument.URL !== new URL(target, location.href).href)+ throw new Error("The iframe did not navigate to target");++ const removedFrame = document.createElement("iframe");+ document.body.append(removedFrame);+ const removedFrameInitialDocument = removedFrame.contentDocument;+ const removedFrameLocation = removedFrame.contentWindow.location;+ await startStalledNavigation(removedFrame, stalledAfterFirstChunk);+ removedFrame.remove();+ while (removedFrameInitialDocument.defaultView) await new Promise(resolve => setTimeout(resolve, 0));+ removedFrameLocation.href = target;++ document.documentElement.classList.remove("test-wait");+ })();+ </script>+ </body>+</html>diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex f5ddaba388e..22a2044e385 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -17,6 +17,7 @@ Text/input/wpt-import/dom/events/event-listener-not-fully-active-navigated.htmlCrash/DOM/shared-resource-request-finalize-while-in-flight.htmlText/input/css/linked-stylesheet-redirect-base-url.htmlText/input/HTML/initial-about-blank-window-outlives-abandoned-navigation.html+Crash/HTML/location-href-setter-during-navigation-from-initial-about-blank.htmlText/input/css/font-cache-first-paint.htmlText/input/css/font-display-timeline.htmlText/input/css/font-cascade-stable-display-period.html