From 185255efc3942b4d49de2faa59691bd9c10c144d Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 5 Nov 2024 07:55:59 -0500 Subject: [PATCH] WebContent: Close top-level traversables asynchronously The spec is a bit out-of-date here, so this works around an issue with closing top-level traversables while a dialog is open in another window within the same agent. --- Userland/Services/WebContent/WebDriverConnection.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 6f1672e10c7..13dfb9103b6 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -460,7 +460,13 @@ Messages::WebDriverClient::CloseWindowResponse WebDriverConnection::close_window // 2. Handle any user prompts and return its value if it is an error. handle_any_user_prompts([this]() { // 3. Close the current top-level browsing context. - current_top_level_browsing_context()->top_level_traversable()->close_top_level_traversable(); + // FIXME: Spec issue: Closing browsing contexts is no longer a spec concept, we must instead close the top-level + // traversable. We must also do so asynchronously, as the implementation will spin the event loop in some + // steps. If a user dialog is open in another window within this agent, the event loop will be paused, and + // those spins will hang. So we must return control to the client, who can deal with the dialog. + Web::HTML::queue_a_task(Web::HTML::Task::Source::Unspecified, nullptr, nullptr, JS::create_heap_function(current_top_level_browsing_context()->heap(), [this]() { + current_top_level_browsing_context()->top_level_traversable()->close_top_level_traversable(); + })); async_driver_execution_complete(JsonValue {}); });