Truly independent web browser
LibWebView: Read a tab's URL from its active session history entry
Shannon Booth27e59fec740b
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cppindex c6e7c480cf5..7653a42d8d7 100644--- a/Libraries/LibWebView/CanonicalNavigable.cpp+++ b/Libraries/LibWebView/CanonicalNavigable.cpp@@ -1334,6 +1334,7 @@ void CanonicalNavigable::set_the_ongoing_navigation(OngoingNavigation value)// 3. Set navigable's ongoing navigation to newValue.m_ongoing_navigation = move(value);+ notify_view_of_ongoing_navigation();if (superseded_navigation && superseded_navigation->ends_when_superseded())end_navigation(*superseded_navigation);@@ -1381,8 +1382,18 @@ void CanonicalNavigable::set_ongoing_navigation_to_traversal(Web::HTML::CrossProvoid CanonicalNavigable::clear_ongoing_navigation_traversal(Web::HTML::CrossProcessId operation_id){- if (auto const* traversal = m_ongoing_navigation.get_pointer<Traversal>(); traversal && traversal->operation_id == operation_id)+ if (auto const* traversal = m_ongoing_navigation.get_pointer<Traversal>(); traversal && traversal->operation_id == operation_id) {m_ongoing_navigation = Empty {};+ notify_view_of_ongoing_navigation();+ }+}++void CanonicalNavigable::notify_view_of_ongoing_navigation() const+{+ if (!is_top_level_traversable())+ return;+ if (auto view = top_level_traversable().view(); view.has_value())+ view->did_change_ongoing_navigation({});}void CanonicalNavigable::clear_ongoing_navigation()@@ -1392,8 +1403,10 @@ void CanonicalNavigable::clear_ongoing_navigation()void CanonicalNavigable::end_navigation(CanonicalNavigation& navigation){- if (auto navigation_id = ongoing_navigation_id(); navigation_id.has_value() && *navigation_id == navigation.navigation_id)+ if (auto navigation_id = ongoing_navigation_id(); navigation_id.has_value() && *navigation_id == navigation.navigation_id) {m_ongoing_navigation = Empty {};+ notify_view_of_ongoing_navigation();+ }auto index = m_navigations.find_first_index_if([&](auto const& candidate) { return candidate.ptr() == &navigation; });VERIFY(index.has_value());auto ended_navigation = m_navigations.take(*index);diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.hindex ffcf9ad9b7a..bf1271a14b9 100644--- a/Libraries/LibWebView/CanonicalNavigable.h+++ b/Libraries/LibWebView/CanonicalNavigable.h@@ -257,6 +257,7 @@ private:RefPtr<CanonicalSessionHistoryEntry> m_current_session_history_entry;RefPtr<CanonicalSessionHistoryEntry> m_active_session_history_entry;void set_the_ongoing_navigation(OngoingNavigation);+ void notify_view_of_ongoing_navigation() const;void end_navigation(CanonicalNavigation&);OngoingNavigation m_ongoing_navigation;Vector<NonnullRefPtr<CanonicalNavigation>> m_navigations;diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cppindex d37b2a7ebd9..870b8e09724 100644--- a/Libraries/LibWebView/CanonicalTraversable.cpp+++ b/Libraries/LibWebView/CanonicalTraversable.cpp@@ -1555,6 +1555,7 @@ void CanonicalTraversable::did_activate_history_entry(HistoryOperation& operatioif (&navigable == this) {if (auto view = this->view(); view.has_value()) {+ view->did_change_active_document({});// NB: The address bar can already show a pending navigation's URL while the old document// is still visible. Only apply the destination's zoom after its document is activated.view->apply_zoom_for_current_host();diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex 22c7ca4a11d..eb60a951267 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -92,6 +92,8 @@ ViewImplementation::ViewImplementation(IsPrivate is_private)ViewImplementation::~ViewImplementation(){+ // The frontend may be torn down already, so clearing the ongoing navigation must not report a URL change to it.+ on_url_change = nullptr;TabPerformanceMonitor::forget_view(view_id());if (m_top_level_traversable)m_top_level_traversable->clear_ongoing_navigation();@@ -146,25 +148,47 @@ WebContentPage& ViewImplementation::page() constreturn *page;}-void ViewImplementation::set_url(URL::URL url)+URL::URL ViewImplementation::url() const{- if (url.fragment().has_value() && url.fragment()->contains(":~:"sv))- m_text_fragment_indication_is_visible = true;+ if (!m_top_level_traversable)+ return URL::about_blank();+ return m_top_level_traversable->active_session_history_entry()->url;+}- if (m_url != url) {- m_url = move(url);- update_bookmark_action();- update_report_website_issue_action();- if (auto page = traversable().display_page(); page && page->routed_connection())- page->routed_connection()->update_audio_capture_permission();- }+void ViewImplementation::did_update_url()+{+ update_bookmark_action();+ update_report_website_issue_action();+ if (auto page = traversable().display_page(); page && page->routed_connection())+ page->routed_connection()->update_audio_capture_permission();+ update_displayed_url();+}++Optional<URL::URL const&> ViewImplementation::browser_ui_load_url() const+{+ if (!m_browser_ui_load.has_value() || !m_top_level_traversable)+ return {};+ auto ongoing_navigation_id = m_top_level_traversable->ongoing_navigation_id();+ if (!ongoing_navigation_id.has_value() || *ongoing_navigation_id != m_browser_ui_load->navigation_id)+ return {};+ return m_browser_ui_load->url;+}+void ViewImplementation::did_change_ongoing_navigation(Badge<CanonicalNavigable>)+{update_displayed_url();}+void ViewImplementation::did_change_active_document(Badge<CanonicalTraversable>)+{+ did_update_url();+}+void ViewImplementation::update_displayed_url(){- auto displayed_url = m_url;+ auto displayed_url = url();+ if (auto browser_ui_load_url = this->browser_ui_load_url(); browser_ui_load_url.has_value())+ displayed_url = *browser_ui_load_url;auto displayed_url_without_fragment_directive = displayed_url;if (auto const& raw_fragment = displayed_url_without_fragment_directive.fragment(); raw_fragment.has_value()) {if (auto position = raw_fragment->find(":~:"sv); position.has_value())@@ -215,8 +239,8 @@ void ViewImplementation::set_favicon(Badge<WebContentPage>, Optional<Gfx::Bitmapif (m_favicon_hash.has_value()) {if (m_is_private == IsPrivate::No)- Application::bookmark_store().update_favicon(m_url, *m_favicon_hash);- m_session->history_store->update_favicon(m_url, *m_favicon_hash);+ Application::bookmark_store().update_favicon(url(), *m_favicon_hash);+ m_session->history_store->update_favicon(url(), *m_favicon_hash);}}@@ -306,8 +330,11 @@ void ViewImplementation::load(Web::HTML::PreparedNavigationDescriptor navigationprepare_for_navigation_after_crash(NavigationToRetry { navigation.url, prepare_navigation_to_retry(navigation) });m_last_stopped_navigation.clear();- if (navigation.url.scheme() != "javascript"sv)- set_url(navigation.url);+ if (navigation.url.scheme() != "javascript"sv) {+ if (navigation.url.fragment().has_value() && navigation.url.fragment()->contains(":~:"sv))+ m_text_fragment_indication_is_visible = true;+ m_browser_ui_load = BrowserUILoad { navigation.navigation_id, navigation.url };+ }traversable().begin_navigation(move(navigation));if (traversable().has_uncommitted_navigation())set_loading_state(true);@@ -497,10 +524,10 @@ void ViewImplementation::did_stop_loading(Badge<CanonicalTraversable>, bool stopdid_end_uncommitted_navigation("stop-loading"sv);}-// The address shown is the current entry's again, and a navigation WebDriver waits on is over.+// The address shown is the active entry's again, and a navigation WebDriver waits on is over.void ViewImplementation::did_end_uncommitted_navigation(StringView reason){- set_url(traversable().session_history().current_entry().url);+ update_displayed_url();if (m_webdriver_navigation_observation.has_value())complete_webdriver_navigation();dump_session_history(reason);@@ -560,7 +587,7 @@ void ViewImplementation::did_not_apply_reload()void ViewImplementation::did_commit_history_step(){- set_url(traversable().session_history().current_entry().url);+ did_update_url();update_navigation_action_state();}@@ -796,7 +823,7 @@ void ViewImplementation::handle_external_url_from_user_input(URL::URL const& url{// Browser UI actions can submit several URLs at once, for example when opening a bookmark folder. Keep those// requests ordered while a handler lookup or confirmation is in progress.- m_pending_external_url_requests.enqueue({ url, m_url.origin(), move(on_handler_unavailable) });+ m_pending_external_url_requests.enqueue({ url, this->url().origin(), move(on_handler_unavailable) });process_next_external_url_request();}@@ -1236,7 +1263,7 @@ ErrorOr<Core::SharedVersionIndex> ViewImplementation::ensure_document_cookie_verCore::SharedVersionIndex document_index = m_document_cookie_version_indices.size();if (!Core::initialize_shared_version(m_document_cookie_version_buffer, document_index)) {- dbgln("Reached maximum document cookie version count for {}, cannot create new version for {}", m_url, domain);+ dbgln("Reached maximum document cookie version count for {}, cannot create new version for {}", url(), domain);return Error::from_string_literal("Reached maximum document cookie version count");}@@ -1439,7 +1466,8 @@ void ViewImplementation::get_source()// Only a website the page is showing can be reported, so not a browser page or a page that crashed.bool ViewImplementation::can_report_website_issue() const{- return (m_url.scheme() == "http"sv || m_url.scheme() == "https"sv) && !crash_overlay_active();+ auto url = this->url();+ return (url.scheme() == "http"sv || url.scheme() == "https"sv) && !crash_overlay_active();}void ViewImplementation::report_website_issue()@@ -3317,7 +3345,8 @@ void ViewImplementation::complete_webdriver_history_traversal(Web::HTML::CrossPrJsonValue ViewImplementation::webdriver_session_history() const{JsonObject serialized;- serialized.set("currentURL"sv, m_url.serialize());+ serialized.set("currentURL"sv, url().serialize());+ serialized.set("displayedURL"sv, m_displayed_url.serialize());serialized.set("webContentProcessID"sv, page().client().pid());serialized.set("backButtonEnabled"sv, m_navigate_back_action->enabled());serialized.set("forwardButtonEnabled"sv, m_navigate_forward_action->enabled());@@ -3357,7 +3386,6 @@ void ViewImplementation::update_navigation_action_state()void ViewImplementation::recover_current_session_history_entry_with_history_operation(){m_history_visit_transition_for_next_load = HistoryVisitTransition::Restore;- set_url(traversable().session_history().current_entry().url);begin_webdriver_navigation(WebDriverNavigationCompletionSource::CrashRecovery);traversable().recover_from_web_content_process_crash();}@@ -3365,7 +3393,6 @@ void ViewImplementation::recover_current_session_history_entry_with_history_opervoid ViewImplementation::reconstruct_current_session_history_entry_with_history_operation(StringView reason){m_history_visit_transition_for_next_load = HistoryVisitTransition::Restore;- set_url(traversable().session_history().current_entry().url);begin_webdriver_navigation(WebDriverNavigationCompletionSource::HistoryTraversal);traversable().reconstruct_the_history_to_step(traversable().session_history().current_step());dump_session_history(reason);@@ -3410,7 +3437,7 @@ bool ViewImplementation::register_session_store_tab_for_testing(Badge<WebContentif (m_session_tab_id.has_value())return true;- auto tab_id = m_session->session_store->tab_opened({ .window_id = {}, .initial_url = m_url, .insertion_index = {}, .is_active = SessionStore::IsActive::No });+ auto tab_id = m_session->session_store->tab_opened({ .window_id = {}, .initial_url = url(), .insertion_index = {}, .is_active = SessionStore::IsActive::No });if (tab_id.is_error())return false;set_session_tab_id(tab_id.value());@@ -3513,7 +3540,7 @@ void ViewImplementation::dump_session_history(StringView reason, SessionHistoryDpage().id(),connection ? connection->pid() : -1,reason,- m_url,+ url(),traversable().has_uncommitted_navigation(),loading_url,traversal.has_value() ? Optional<i32> { traversal->target_step } : Optional<i32> {},@@ -3526,7 +3553,9 @@ void ViewImplementation::dump_session_history(StringView reason, SessionHistoryDvoid ViewImplementation::handle_web_content_process_crash(){- auto failed_url = m_url;+ auto failed_url = url();+ if (auto browser_ui_load_url = this->browser_ui_load_url(); browser_ui_load_url.has_value())+ failed_url = *browser_ui_load_url;Optional<NavigationToRetry> navigation_to_retry;if (traversable().session_history().current_entry().url != failed_url) {navigation_to_retry = NavigationToRetry { failed_url, {} };@@ -3680,7 +3709,7 @@ void ViewImplementation::did_save_crash_report(ByteString report_name)String ViewImplementation::crash_overlay_failed_url() const{- return m_crash_state.has_value() ? m_crash_state->failed_url.serialize() : m_url.serialize();+ return m_crash_state.has_value() ? m_crash_state->failed_url.serialize() : url().serialize();}Optional<ByteString> ViewImplementation::crash_report_name() constdiff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex 32797c1d70e..eb324334844 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -123,10 +123,12 @@ public:void did_change_display_page(Badge<CanonicalNavigable>, RefPtr<WebContentPage> previous_page);void did_cancel_loading(Badge<CanonicalNavigable>, bool canceled_navigation);void did_stop_loading(Badge<CanonicalTraversable>, bool stopped_navigation);+ void did_change_ongoing_navigation(Badge<CanonicalNavigable>);+ void did_change_active_document(Badge<CanonicalTraversable>);- void set_url(Badge<WebContentPage>, URL::URL url) { set_url(move(url)); }void set_text_fragment_indication_visibility(Badge<WebContentPage>, bool);- URL::URL const& url() const { return m_url; }+ // The URL of the tab's active session history entry.+ URL::URL url() const;URL::URL const& displayed_url() const { return m_displayed_url; }void set_title(Badge<WebContentPage>, Utf16String title);@@ -623,7 +625,8 @@ protected:void set_owner_view(ViewImplementation const& owner_view) { m_owner_view_id = owner_view.view_id(); }- void set_url(URL::URL);+ void did_update_url();+ Optional<URL::URL const&> browser_ui_load_url() const;void update_displayed_url();void did_start_navigation();void did_finish_navigation();@@ -757,7 +760,12 @@ protected:IsPrivate m_is_private { IsPrivate::No };NonnullRefPtr<BrowsingSession> m_session;- URL::URL m_url { URL::about_blank() };+ // A load the browser's UI started, whose URL the address bar shows while it is the ongoing navigation.+ struct BrowserUILoad {+ Utf16String navigation_id;+ URL::URL url;+ };+ Optional<BrowserUILoad> m_browser_ui_load;URL::URL m_displayed_url { URL::about_blank() };bool m_text_fragment_indication_is_visible { false };Utf16String m_title;diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cppindex 9ca99c3bc42..22d7a6e8cf2 100644--- a/Libraries/LibWebView/WebContentPage.cpp+++ b/Libraries/LibWebView/WebContentPage.cpp@@ -447,7 +447,6 @@ void WebContentPage::begin_top_level_load(URL::URL const& url)view.m_history_visit_transition_for_next_load = HistoryVisitTransition::Link;view.did_start_navigation();- view.set_url({}, url);view.set_title({}, Utf16String::from_utf8(url.serialize()));view.set_favicon({}, {});view.set_editing_history_state(false, false);diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 6201b18df53..5f7100ec434 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -15,6 +15,7 @@ Ref/expected/font-display-periods-ref.htmlText/input/cookie-cache-invalidation.htmlText/input/cookie-working.htmlText/input/cookie-store-empty-domain.html+Text/input/cookie-change-events-skip-pending-navigation-url.htmlText/input/wpt-import/cookies/attributes/domain.sub.html; Performs cross-origin Worker fetchdiff --git a/Tests/LibWeb/Text/expected/cookie-change-events-skip-pending-navigation-url.txt b/Tests/LibWeb/Text/expected/cookie-change-events-skip-pending-navigation-url.txtnew file mode 100644index 00000000000..75e330590f1--- /dev/null+++ b/Tests/LibWeb/Text/expected/cookie-change-events-skip-pending-navigation-url.txt@@ -0,0 +1 @@+Changes seen by the document being navigated away from: controldiff --git a/Tests/LibWeb/Text/input/cookie-change-events-skip-pending-navigation-url.html b/Tests/LibWeb/Text/input/cookie-change-events-skip-pending-navigation-url.htmlnew file mode 100644index 00000000000..05a0c5237cc--- /dev/null+++ b/Tests/LibWeb/Text/input/cookie-change-events-skip-pending-navigation-url.html@@ -0,0 +1,83 @@+<!DOCTYPE html>+<script src="include.js"></script>+<script>+ // A document whose navigation has not committed yet only gets change events for the cookies of its own URL.+ asyncTest(async done => {+ const server = httpTestServer();+ const runId = crypto.randomUUID();+ const cookieSite = uniqueLocalhostHostname("cookie-change-pending");+ const token = `cookie-change-pending-${runId}`;++ const onCookieSite = url => {+ const result = new URL(url);+ result.hostname = cookieSite;+ return result.href;+ };++ const pendingURL = onCookieSite(+ await server.createEcho("GET", `/cookie-change-pending/${runId}/pending/target.html`, {+ status: 200,+ headers: { "Content-Type": "text/html", "Cache-Control": "no-store" },+ body: "<!DOCTYPE html>",+ wait_for_unblock: token,+ })+ );+ const pendingPath = new URL(pendingURL).pathname.replace(/target\.html$/, "");++ const currentURL = onCookieSite(+ await server.createEcho("GET", `/cookie-change-pending/${runId}/current/top-level.html`, {+ status: 200,+ headers: { "Content-Type": "text/html", "Cache-Control": "no-store" },+ body: `<!DOCTYPE html><script>+ cookieStore.addEventListener("change", event => {+ for (const cookie of event.changed)+ opener.postMessage({ changed: cookie.name }, "*");+ });+ window.addEventListener("message", event => {+ if (event.data === "navigate") {+ location.href = ${JSON.stringify(pendingURL)};+ } else if (event.data === "set-cookies") {+ document.cookie = "pending=1; path=${pendingPath}";+ document.cookie = "control=1; path=/";+ }+ });+ opener.postMessage("ready", "*");+ <\/script>`,+ })+ );++ const nextMessage = predicate =>+ new Promise(resolve => {+ window.addEventListener("message", function listener(event) {+ if (!predicate(event.data))+ return;+ window.removeEventListener("message", listener);+ resolve(event.data);+ });+ });++ let message = nextMessage(data => data === "ready");+ const popup = window.open(currentURL);+ await message;++ const changes = [];+ window.addEventListener("message", event => {+ if (event.data?.changed)+ changes.push(event.data.changed);+ });++ popup.postMessage("navigate", "*");+ const recordedRequestHeadersURL = server.recordedRequestHeadersURL(pendingURL);+ while (!(await fetch(recordedRequestHeadersURL)).ok) { }++ message = nextMessage(data => data?.changed === "control");+ popup.postMessage("set-cookies", "*");+ await message;++ println(`Changes seen by the document being navigated away from: ${changes.join(", ")}`);++ await fetch(new URL(`/unblock/${token}`, server.baseURL));+ popup.close();+ done();+ });+</script>diff --git a/Tests/LibWebView/test-webdriver-session-history.py b/Tests/LibWebView/test-webdriver-session-history.pyindex 7cc40018bef..334d66092c0 100755--- a/Tests/LibWebView/test-webdriver-session-history.py+++ b/Tests/LibWebView/test-webdriver-session-history.py@@ -984,10 +984,12 @@ def refresh(webdriver_port, session_id):request(webdriver_port, "POST", f"/session/{session_id}/refresh", {})-def create_session(webdriver_port, enable_test_hooks=True, beforeunload_prompt_handler=None):+def create_session(+ webdriver_port, enable_test_hooks=True, beforeunload_prompt_handler=None, page_load_strategy="normal"+):always_match = {"ladybird:headless": True,- "pageLoadStrategy": "normal",+ "pageLoadStrategy": page_load_strategy,}if enable_test_hooks:always_match["ladybird:enableTestHooks"] = True@@ -2282,10 +2284,7 @@ return null;)pending_history = session_history(webdriver_port, session_id)- if pending_history["ui"]["currentURL"] not in (- url_navigation_blocked,- url_redirect_to_navigation_blocked,- ) or history_entry_urls(pending_history["ui"]) != [url_a]:+ if pending_history["ui"]["currentURL"] != url_a or history_entry_urls(pending_history["ui"]) != [url_a]:raise AssertionError(f"Expected {label} to leave canonical history at /a, got "f"{summarize_history_snapshot(pending_history)}\n" + "\n".join(log)@@ -2462,7 +2461,6 @@ def run_cross_process_pending_navigation_browser_ui_back_test(webdriver_port,page_server,url_a,- url_cross_site_navigation_blocked,):session_id = create_session(webdriver_port)log = [f"cross-process pending navigation browser UI back initial: {current_url(webdriver_port, session_id)}"]@@ -2495,7 +2493,7 @@ def run_cross_process_pending_navigation_browser_ui_back_test(# The endpoint has not sent response headers yet. Keep the current host until the response URL is known and# process placement can be selected from it.if (- pending_history["ui"]["currentURL"] != url_cross_site_navigation_blocked+ pending_history["ui"]["currentURL"] != url_aor history_entry_urls(pending_history["ui"]) != [url_a]or pending_history["ui"]["webContentProcessID"] != initial_process_id):@@ -2550,7 +2548,6 @@ def run_cross_process_no_content_navigation_restore_test(webdriver_port,page_server,url_a,- url_cross_site_no_content,):session_id = create_session(webdriver_port)log = [f"cross-process no-content navigation restore initial: {current_url(webdriver_port, session_id)}"]@@ -2580,7 +2577,7 @@ def run_cross_process_no_content_navigation_restore_test(pending_history = session_history(webdriver_port, session_id)if (- pending_history["ui"]["currentURL"] != url_cross_site_no_content+ pending_history["ui"]["currentURL"] != url_aor history_entry_urls(pending_history["ui"]) != [url_a]or pending_history["ui"]["webContentProcessID"] != initial_process_id):@@ -2618,6 +2615,84 @@ def run_cross_process_no_content_navigation_restore_test(request(webdriver_port, "DELETE", f"/session/{session_id}")+def run_pending_ui_load_test(webdriver_port, page_server, url_a, url_navigation_blocked):+ # A load from the browser's UI returns as soon as it starts, so the document it replaces can run script meanwhile.+ session_id = create_session(webdriver_port, page_load_strategy="none")+ log = [f"pending UI load initial: {current_url(webdriver_port, session_id)}"]+ try:+ page_server.a_document_ran.clear()+ load_url_from_ui(webdriver_port, session_id, url_a)+ wait_for_event(page_server.a_document_ran, "A document before pending UI load")++ page_server.blocked_navigation_requested.clear()+ page_server.release_blocked_navigation.clear()+ load_url_from_ui(webdriver_port, session_id, url_navigation_blocked)+ wait_for_event(page_server.blocked_navigation_requested, "pending UI load request")++ pending_history = session_history(webdriver_port, session_id)["ui"]+ if pending_history["currentURL"] != url_a or pending_history["displayedURL"] != url_navigation_blocked:+ raise AssertionError(+ f"Expected the pending UI load to show only in the address bar, got {pending_history}\n"+ + "\n".join(log)+ )++ # A cookie only the pending URL matches, then one the current document's URL matches.+ changes = execute_async_script(+ webdriver_port,+ session_id,+ """+const done = arguments[arguments.length - 1];+const changes = [];+cookieStore.addEventListener("change", event => {+ for (const cookie of event.changed) {+ changes.push(cookie.name);+ if (cookie.name === "control")+ done(changes.join(", "));+ }+});+document.cookie = "pending=1; path=/navigation-blocked";+document.cookie = "control=1; path=/";+""",+ )+ if changes != "control":+ raise AssertionError(+ f"Expected the document being navigated away from to see only its own cookie change, got {changes}\n"+ + "\n".join(log)+ )++ # A navigation the page starts takes over from the pending UI load, whose URL the address bar stops showing.+ page_server.blocked_no_content_navigation_requested.clear()+ page_server.release_blocked_no_content_navigation.clear()+ execute_script(+ webdriver_port,+ session_id,+ 'location.href = "/navigation-no-content-blocked"; return null;',+ )+ wait_for_event(page_server.blocked_no_content_navigation_requested, "page-initiated navigation request")++ superseded_history = session_history(webdriver_port, session_id)["ui"]+ if superseded_history["currentURL"] != url_a or superseded_history["displayedURL"] != url_a:+ raise AssertionError(+ f"Expected the address bar to stop showing the superseded UI load, got {superseded_history}\n"+ + "\n".join(log)+ )++ page_server.release_blocked_no_content_navigation.set()+ execute_script(+ webdriver_port,+ session_id,+ """+document.cookie = "pending=; path=/navigation-blocked; max-age=0";+document.cookie = "control=; path=/; max-age=0";+return null;+""",+ )+ finally:+ page_server.release_blocked_navigation.set()+ page_server.release_blocked_no_content_navigation.set()+ request(webdriver_port, "DELETE", f"/session/{session_id}")++def run_uncommitted_navigation_browser_ui_back_tests(webdriver_port,page_server,@@ -2625,7 +2700,6 @@ def run_uncommitted_navigation_browser_ui_back_tests(url_d,url_navigation_blocked,url_redirect_to_navigation_blocked,- url_cross_site_navigation_blocked,):run_pending_navigation_browser_ui_back_test(webdriver_port,@@ -2644,13 +2718,11 @@ def run_uncommitted_navigation_browser_ui_back_tests(webdriver_port,page_server,url_a,- url_cross_site_navigation_blocked,)run_cross_process_no_content_navigation_restore_test(webdriver_port,page_server,url_a,- f"http://127.0.0.1:{page_server.server_port}/navigation-no-content-blocked",)@@ -2848,7 +2920,6 @@ def run_test(webdriver_binary):url_d = f"http://localhost:{page_port}/d"url_redirect_to_b = f"http://localhost:{page_port}/redirect-to-b"url_navigation_blocked = f"http://localhost:{page_port}/navigation-blocked"- url_cross_site_navigation_blocked = f"http://127.0.0.1:{page_port}/navigation-blocked"url_redirect_to_navigation_blocked = f"http://localhost:{page_port}/redirect-to-navigation-blocked"url_nested = f"http://localhost:{page_port}/nested"url_state = f"http://localhost:{page_port}/state"@@ -2897,8 +2968,8 @@ def run_test(webdriver_binary):url_d,url_navigation_blocked,url_redirect_to_navigation_blocked,- url_cross_site_navigation_blocked,)+ run_pending_ui_load_test(webdriver_port, page_server, url_a, url_navigation_blocked)session_id = create_session(webdriver_port)expect_second_ui_forward_supersedes_pending_forward(diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cppindex 702151f4651..c1a556f790e 100644--- a/UI/Qt/Tab.cpp+++ b/UI/Qt/Tab.cpp@@ -1428,7 +1428,7 @@ void Tab::location_edit_return_pressed(String input, Optional<URL::URL> fallbackauto is_external_url = destination_kind == WebView::OmniboxDestinationKind::URL&& WebView::classify_user_input(input).classification == WebView::UserInputClassification::ExternalURL;if (is_external_url)- m_location_edit->set_url(view().url());+ m_location_edit->set_url(view().displayed_url());view().setFocus();}