From 4c61ce5b10725511e167f8a12c947b0b3ba484e6 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 5 Nov 2024 07:47:51 -0500 Subject: [PATCH] WebDriver: Don't remove windows if attempting to close the window failed For example, if a dialog is open and the session is configured to ignore dialogs (instead of automatically closing them), then the Close Window endpoint will have failed. We can't remove the client-side window handle in that case. --- Userland/Services/WebDriver/Session.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Services/WebDriver/Session.cpp b/Userland/Services/WebDriver/Session.cpp index e251473e23c..4cfc160b146 100644 --- a/Userland/Services/WebDriver/Session.cpp +++ b/Userland/Services/WebDriver/Session.cpp @@ -193,15 +193,15 @@ Web::WebDriver::Response Session::set_timeouts(JsonValue payload) // 11.2 Close Window, https://w3c.github.io/webdriver/#dfn-close-window Web::WebDriver::Response Session::close_window() { + // 3. Close the current top-level browsing context. + TRY(perform_async_action([&](auto& connection) { + return connection.close_window(); + })); + { // Defer removing the window handle from this session until after we know we are done with its connection. ScopeGuard guard { [this] { m_windows.remove(m_current_window_handle); m_current_window_handle = "NoSuchWindowPleaseSelectANewOne"_string; } }; - // 3. Close the current top-level browsing context. - TRY(perform_async_action([&](auto& connection) { - return connection.close_window(); - })); - // 4. If there are no more open top-level browsing contexts, then close the session. if (m_windows.size() == 1) m_client->close_session(session_id());