RESOLVED FIXED294044
[WebDriver][GLIB] Notify automation session on abnormal disconnections from the browser
https://bugs.webkit.org/show_bug.cgi?id=294044
Summary [WebDriver][GLIB] Notify automation session on abnormal disconnections from t...
Lauro Moura
Reported 2025-06-04 12:54:27 PDT
Last year, we added support to connect a new WebDriver session to an already running browser. This is done by spawning the browser - apart from the driver - with the remote inspector server already up and using the `--target` flag to the WebDriver service. This feature is working fine for _clean_ WebDriver runs, where we have the following shutdown chain: - The driver service sends the "delete session" command - `WebAutomationSession::deleteSession(...)` - `WebAutomationSession::terminate()` - `AutomationSessionClient::didDisconnectFromRemote()` - Emit `WebKitAutomationSession::will-close` no notify the browser to perform the proper cleanup steps, like destroying automated views - Clean the `WebAutomationSession` held by the `WebProcessPool` and the `WebKitAutomationSession` held by `WebKitWebContext`. This is enough to free up the browser-side automation session when the WebDriver session client closes. The problem arises when the connection is closed abruptly. For example, due to the driver crashing (see bug293703) or, easier to reproduce, failure to match capabilities. In this scenario, we have a "zombie" `WebKitAutomationSession`/`WebAutomationSession` pair in the running browser. And if we try to reconnect to the same browser, we either get a "The remote session failed to create a new browsing context." error, or, if we have assertions enabled, we hit an assertion in `WebKitAutomationClient::requestAutomationSession` in `WebKitWebContext.cpp` due to the existing `WebKitAutomationSession`. To ensure we are notified of such disconnections, we could: - Add a method like `RemoteInspector::automationConnectionDidClose()`, which is called from `RemoteInspectorServer::connectionDidClose()` when, well, the automation connection is closed. - This is similar to what we already do for incoming connections, with the `RemoteInspector::requestAutomationSession(sessionID, capabilities)` method. - Make `WebKitAutomationClient` implement `RemoteInspector::Client::closeAutomationSession`, which is called by the `RemoteInspector::automationConnectionDidClose()` created in the previous item - And for completeness, make `RemoteInspectorServer` check the outcome of the `startAutomationSession` & friends, as it might not make sense to continue the start process if we failed to create a new automation session instance. Patch incoming.
Attachments
Lauro Moura
Comment 1 2025-06-05 20:28:25 PDT
EWS
Comment 2 2025-06-11 11:29:06 PDT
Committed 296096@main (20fa2504d9b7): <https://commits.webkit.org/296096@main> Reviewed commits have been landed. Closing PR #46402 and removing active labels.
Radar WebKit Bug Importer
Comment 3 2025-06-11 11:31:44 PDT
Note You need to log in before you can comment on or make changes to this bug.