@@ -121,6 +121,8 @@ public class LocalNode extends Node {
121121 private final int maxSessionCount ;
122122 private final int configuredSessionCount ;
123123 private final boolean cdpEnabled ;
124+
125+ private final boolean bidiEnabled ;
124126 private final AtomicBoolean drainAfterSessions = new AtomicBoolean ();
125127 private final List <SessionSlot > factories ;
126128 private final Cache <SessionId , SessionSlot > currentSessions ;
@@ -137,6 +139,7 @@ private LocalNode(
137139 int maxSessionCount ,
138140 int drainAfterSessionCount ,
139141 boolean cdpEnabled ,
142+ boolean bidiEnabled ,
140143 Ticker ticker ,
141144 Duration sessionTimeout ,
142145 Duration heartbeatPeriod ,
@@ -157,6 +160,7 @@ private LocalNode(
157160 this .drainAfterSessions .set (this .configuredSessionCount > 0 );
158161 this .sessionCount .set (drainAfterSessionCount );
159162 this .cdpEnabled = cdpEnabled ;
163+ this .bidiEnabled = bidiEnabled ;
160164
161165 this .healthCheck = healthCheck == null ?
162166 () -> {
@@ -390,6 +394,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
390394 session ,
391395 externalUri ,
392396 slotToUse .isSupportingCdp (),
397+ slotToUse .isSupportingBiDi (),
393398 sessionRequest .getDesiredCapabilities ());
394399
395400 String sessionCreatedMessage = "Session created by the Node" ;
@@ -427,6 +432,7 @@ public Session getSession(SessionId id) throws NoSuchSessionException {
427432 slot .getSession (),
428433 externalUri ,
429434 slot .isSupportingCdp (),
435+ slot .isSupportingBiDi (),
430436 slot .getSession ().getCapabilities ());
431437 }
432438
@@ -515,8 +521,11 @@ private void stopAllSessions() {
515521 }
516522 }
517523
518- private Session createExternalSession (ActiveSession other , URI externalUri ,
519- boolean isSupportingCdp , Capabilities requestCapabilities ) {
524+ private Session createExternalSession (ActiveSession other ,
525+ URI externalUri ,
526+ boolean isSupportingCdp ,
527+ boolean isSupportingBiDi ,
528+ Capabilities requestCapabilities ) {
520529 // We merge the session request capabilities and the session ones to keep the values sent
521530 // by the user in the session information
522531 Capabilities toUse = ImmutableCapabilities
@@ -535,6 +544,21 @@ private Session createExternalSession(ActiveSession other, URI externalUri,
535544 }
536545 });
537546 toUse = new PersistentCapabilities (cdpFiltered ).setCapability ("se:cdpEnabled" , false );
547+ }
548+
549+ // Add se:bidi if necessary to send the bidi url back
550+ if ((isSupportingBiDi || toUse .getCapability ("se:bidi" ) != null ) && bidiEnabled ) {
551+ String bidiPath = String .format ("/session/%s/se/bidi" , other .getId ());
552+ toUse = new PersistentCapabilities (toUse ).setCapability ("se:bidi" , rewrite (bidiPath ));
553+ } else {
554+ // Remove any se:bidi* from the response, BiDi is not supported nor enabled
555+ MutableCapabilities bidiFiltered = new MutableCapabilities ();
556+ toUse .asMap ().forEach ((key , value ) -> {
557+ if (!key .startsWith ("se:bidi" )) {
558+ bidiFiltered .setCapability (key , value );
559+ }
560+ });
561+ toUse = new PersistentCapabilities (bidiFiltered ).setCapability ("se:bidiEnabled" , false );
538562 }
539563
540564 // If enabled, set the VNC endpoint for live view
@@ -665,6 +689,7 @@ public static class Builder {
665689 private int maxSessions = NodeOptions .DEFAULT_MAX_SESSIONS ;
666690 private int drainAfterSessionCount = NodeOptions .DEFAULT_DRAIN_AFTER_SESSION_COUNT ;
667691 private boolean cdpEnabled = NodeOptions .DEFAULT_ENABLE_CDP ;
692+ private boolean bidiEnabled = NodeOptions .DEFAULT_ENABLE_BIDI ;
668693 private Ticker ticker = Ticker .systemTicker ();
669694 private Duration sessionTimeout = Duration .ofSeconds (NodeOptions .DEFAULT_SESSION_TIMEOUT );
670695 private HealthCheck healthCheck ;
@@ -708,6 +733,11 @@ public Builder enableCdp(boolean cdpEnabled) {
708733 return this ;
709734 }
710735
736+ public Builder enableBiDi (boolean bidiEnabled ) {
737+ this .bidiEnabled = bidiEnabled ;
738+ return this ;
739+ }
740+
711741 public Builder sessionTimeout (Duration timeout ) {
712742 sessionTimeout = timeout ;
713743 return this ;
@@ -728,6 +758,7 @@ public LocalNode build() {
728758 maxSessions ,
729759 drainAfterSessionCount ,
730760 cdpEnabled ,
761+ bidiEnabled ,
731762 ticker ,
732763 sessionTimeout ,
733764 heartbeatPeriod ,
0 commit comments