From 47e9357243c5e561576d03ed8d1c444076847272 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 18 Sep 2024 14:15:23 -0400 Subject: [PATCH] WebContent: Search all known navigables when WebDriver switches windows We were only looking at the current top-level navigable and its children when searching for the specified window handle. We need to search *all* known navigables if the handle belongs to a window not in the current tree. --- .../Services/WebContent/WebDriverConnection.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index c91595d8283..ec73973ccda 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -449,16 +449,16 @@ Messages::WebDriverClient::SwitchToWindowResponse WebDriverConnection::switch_to // Otherwise, return error with error code no such window. bool found_matching_context = false; - if (auto browsing_context = current_top_level_browsing_context()) { - browsing_context->for_each_in_inclusive_subtree([&](Web::HTML::BrowsingContext& context) { - if (handle != context.top_level_traversable()->window_handle()) - return Web::TraversalDecision::Continue; + for (auto* navigable : Web::HTML::all_navigables()) { + auto traversable = navigable->top_level_traversable(); + if (!traversable || !traversable->active_browsing_context()) + continue; - m_current_browsing_context = context; + if (handle == traversable->window_handle()) { + m_current_browsing_context = traversable->active_browsing_context(); found_matching_context = true; - - return Web::TraversalDecision::Break; - }); + break; + } } if (!found_matching_context)