diff --git a/java/src/org/openqa/selenium/bidi/BiDiProvider.java b/java/src/org/openqa/selenium/bidi/BiDiProvider.java index c23ffa554bfcc..ae1ac58d7f901 100644 --- a/java/src/org/openqa/selenium/bidi/BiDiProvider.java +++ b/java/src/org/openqa/selenium/bidi/BiDiProvider.java @@ -56,14 +56,8 @@ public HasBiDi getImplementation(Capabilities caps, ExecuteMethod executeMethod) } private Optional getBiDiUrl(Capabilities caps) { - Object bidiCapability; - if (caps.asMap().containsKey("se:bidi")) { - // Session is created remotely - bidiCapability = caps.getCapability("se:bidi"); - } else { - bidiCapability = caps.getCapability("webSocketUrl"); - } - Optional webSocketUrl = Optional.ofNullable((String) bidiCapability); + Object biDiCapability = caps.getCapability("webSocketUrl"); + Optional webSocketUrl = Optional.ofNullable((String) biDiCapability); return webSocketUrl.map( uri -> { diff --git a/java/src/org/openqa/selenium/grid/node/ProxyNodeWebsockets.java b/java/src/org/openqa/selenium/grid/node/ProxyNodeWebsockets.java index 82cc397772c22..1101dca55056a 100644 --- a/java/src/org/openqa/selenium/grid/node/ProxyNodeWebsockets.java +++ b/java/src/org/openqa/selenium/grid/node/ProxyNodeWebsockets.java @@ -171,7 +171,7 @@ private Optional> findBiDiEndpoint( Consumer sessionConsumer, SessionId sessionId) { try { - URI uri = new URI(String.valueOf(caps.getCapability("webSocketUrl"))); + URI uri = new URI(String.valueOf(caps.getCapability("se:gridWebSocketUrl"))); return Optional.of(uri) .map(bidi -> createWsEndPoint(bidi, downstream, sessionConsumer, sessionId)); } catch (URISyntaxException e) { diff --git a/java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java b/java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java index 58044d4752770..8648247f315c9 100644 --- a/java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java +++ b/java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java @@ -22,7 +22,6 @@ import static org.openqa.selenium.remote.tracing.Tags.EXCEPTION; import java.net.URI; -import java.net.URISyntaxException; import java.net.URL; import java.time.Duration; import java.time.Instant; @@ -186,7 +185,6 @@ public Either apply(CreateSessionRequest sess } caps = readDevToolsEndpointAndVersion(caps); - caps = readBiDiEndpoint(caps); caps = readVncEndpoint(capabilities, caps); span.addEvent("Driver service created session", attributeMap); @@ -281,29 +279,6 @@ public DevToolsInfo(URI cdpEndpoint, String version) { return caps; } - private Capabilities readBiDiEndpoint(Capabilities caps) { - - Optional webSocketUrl = - Optional.ofNullable((String) caps.getCapability("webSocketUrl")); - - Optional websocketUri = - webSocketUrl.map( - uri -> { - try { - return new URI(uri); - } catch (URISyntaxException e) { - LOG.warning(e.getMessage()); - } - return null; - }); - - if (websocketUri.isPresent()) { - return new PersistentCapabilities(caps).setCapability("se:bidi", websocketUri.get()); - } - - return caps; - } - private Capabilities readVncEndpoint(Capabilities requestedCaps, Capabilities returnedCaps) { String seVncEnabledCap = "se:vncEnabled"; String seNoVncPortCap = "se:noVncPort"; diff --git a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java index 0e5d283158536..79f687448cf91 100644 --- a/java/src/org/openqa/selenium/grid/node/local/LocalNode.java +++ b/java/src/org/openqa/selenium/grid/node/local/LocalNode.java @@ -805,20 +805,34 @@ private Session createExternalSession( } // Check if the user wants to use BiDi - boolean webSocketUrl = toUse.asMap().containsKey("webSocketUrl"); - // Add se:bidi if necessary to send the bidi url back - boolean bidiSupported = isSupportingBiDi || toUse.getCapability("se:bidi") != null; - if (bidiSupported && bidiEnabled && webSocketUrl) { + // This will be null if the user has not set the capability. + Object webSocketUrl = toUse.getCapability("webSocketUrl"); + + // In case of Firefox versions that do not support webSocketUrl, it returns the capability as it + // is i.e. boolean value. So need to check if it is a string. + // Check if the Node supports BiDi and if the client wants to use BiDi. + boolean bidiSupported = isSupportingBiDi && (webSocketUrl instanceof String); + if (bidiSupported && bidiEnabled) { + String biDiUrl = (String) other.getCapabilities().getCapability("webSocketUrl"); + URI uri = null; + try { + uri = new URI(biDiUrl); + } catch (URISyntaxException e) { + throw new IllegalArgumentException("Unable to create URI from " + uri); + } String bidiPath = String.format("/session/%s/se/bidi", other.getId()); - toUse = new PersistentCapabilities(toUse).setCapability("se:bidi", rewrite(bidiPath)); + toUse = + new PersistentCapabilities(toUse) + .setCapability("se:gridWebSocketUrl", uri) + .setCapability("webSocketUrl", rewrite(bidiPath)); } else { - // Remove any se:bidi* from the response, BiDi is not supported nor enabled + // Remove any "webSocketUrl" from the response, BiDi is not supported nor enabled MutableCapabilities bidiFiltered = new MutableCapabilities(); toUse .asMap() .forEach( (key, value) -> { - if (!key.startsWith("se:bidi")) { + if (!key.startsWith("webSocketUrl")) { bidiFiltered.setCapability(key, value); } });