From e8e1bc42e72a7ac629e9990409e6ae0a02c3429c Mon Sep 17 00:00:00 2001 From: Simon Mavi Stewart Date: Tue, 28 Sep 2021 11:30:01 +0100 Subject: [PATCH] [cdp] Handle the case where the original endpoint is unreachable --- .../openqa/selenium/devtools/CdpEndpointFinder.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/java/src/org/openqa/selenium/devtools/CdpEndpointFinder.java b/java/src/org/openqa/selenium/devtools/CdpEndpointFinder.java index 75a1f786def1c..ef4d131aca6e6 100644 --- a/java/src/org/openqa/selenium/devtools/CdpEndpointFinder.java +++ b/java/src/org/openqa/selenium/devtools/CdpEndpointFinder.java @@ -25,6 +25,8 @@ import org.openqa.selenium.remote.http.HttpRequest; import org.openqa.selenium.remote.http.HttpResponse; +import java.io.IOException; +import java.io.UncheckedIOException; import java.net.URI; import java.net.URISyntaxException; import java.util.Map; @@ -48,7 +50,13 @@ public static Optional getCdpEndPoint(HttpClient.Factory clientFactory, URI ClientConfig config = ClientConfig.defaultConfig().baseUri(reportedUri); HttpClient client = clientFactory.createClient(config); - HttpResponse res = client.execute(new HttpRequest(GET, "/json/version")); + HttpResponse res; + try { + res = client.execute(new HttpRequest(GET, "/json/version")); + } catch (UncheckedIOException e) { + LOG.warning("Unable to connect to determine websocket url: " + e.getMessage()); + return Optional.empty(); + } if (res.getStatus() != HTTP_OK) { return Optional.empty(); }