make driver.close() tolerant to CDP failures
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)
[skip ci]
import org.openqa.selenium.logging.NeedsLocalLogs;
import org.openqa.selenium.print.PrintOptions;
import org.openqa.selenium.remote.http.ClientConfig;
+import org.openqa.selenium.remote.http.ConnectionFailedException;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.internal.WebElementToJsonConverter;
import org.openqa.selenium.remote.tracing.TracedHttpClient;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import static java.util.logging.Level.SEVERE;
+
@Augmentable
public class RemoteWebDriver implements WebDriver,
JavascriptExecutor,
@@ -437,8 +440,14 @@ public void close() {
// first browser window is closed, the next CDP command will hang
// indefinitely. To prevent that from happening, we close the current
// connection. The next CDP command _should_ make us reconnect
+
+ try {
((HasDevTools) this).maybeGetDevTools().ifPresent(DevTools::disconnectSession);
}
+ catch (ConnectionFailedException unableToEstablishWebsocketConnection) {
+ logger.log(SEVERE, "Failed to disconnect DevTools session", unableToEstablishWebsocketConnection);
+ }
+ }
execute(DriverCommand.CLOSE);
}
