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.
This commit is contained in:
Timothy Flynn 2024-11-05 07:47:51 -05:00 committed by Andrew Kaster
parent 7f4d2ef0d6
commit 4c61ce5b10
Notes: github-actions[bot] 2024-11-05 19:07:03 +00:00

View file

@ -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());