Skip to content

Commit 635363b

Browse files
authored
#10345 make driver.close() tolerant to CDP failures (#10346)
Driver should still be closed even if failed to disconnect DevTools session (which apparently happens because Selenium doesn't support current version of browser's CDP) Co-authored-by: Diego Molina <[email protected]> [skip ci]
1 parent 897caec commit 635363b

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

java/src/org/openqa/selenium/remote/RemoteWebDriver.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import org.openqa.selenium.logging.NeedsLocalLogs;
6868
import org.openqa.selenium.print.PrintOptions;
6969
import org.openqa.selenium.remote.http.ClientConfig;
70+
import org.openqa.selenium.remote.http.ConnectionFailedException;
7071
import org.openqa.selenium.remote.http.HttpClient;
7172
import org.openqa.selenium.remote.internal.WebElementToJsonConverter;
7273
import org.openqa.selenium.remote.tracing.TracedHttpClient;
@@ -96,6 +97,8 @@
9697
import java.util.stream.Collectors;
9798
import java.util.stream.Stream;
9899

100+
import static java.util.logging.Level.SEVERE;
101+
99102
@Augmentable
100103
public class RemoteWebDriver implements WebDriver,
101104
JavascriptExecutor,
@@ -437,7 +440,13 @@ public void close() {
437440
// first browser window is closed, the next CDP command will hang
438441
// indefinitely. To prevent that from happening, we close the current
439442
// connection. The next CDP command _should_ make us reconnect
440-
((HasDevTools) this).maybeGetDevTools().ifPresent(DevTools::disconnectSession);
443+
444+
try {
445+
((HasDevTools) this).maybeGetDevTools().ifPresent(DevTools::disconnectSession);
446+
}
447+
catch (ConnectionFailedException unableToEstablishWebsocketConnection) {
448+
logger.log(SEVERE, "Failed to disconnect DevTools session", unableToEstablishWebsocketConnection);
449+
}
441450
}
442451

443452
execute(DriverCommand.CLOSE);

0 commit comments

Comments
 (0)