@@ -121,6 +121,8 @@ public class LocalNode extends Node {
121
121
private final int maxSessionCount ;
122
122
private final int configuredSessionCount ;
123
123
private final boolean cdpEnabled ;
124
+
125
+ private final boolean bidiEnabled ;
124
126
private final AtomicBoolean drainAfterSessions = new AtomicBoolean ();
125
127
private final List <SessionSlot > factories ;
126
128
private final Cache <SessionId , SessionSlot > currentSessions ;
@@ -137,6 +139,7 @@ private LocalNode(
137
139
int maxSessionCount ,
138
140
int drainAfterSessionCount ,
139
141
boolean cdpEnabled ,
142
+ boolean bidiEnabled ,
140
143
Ticker ticker ,
141
144
Duration sessionTimeout ,
142
145
Duration heartbeatPeriod ,
@@ -157,6 +160,7 @@ private LocalNode(
157
160
this .drainAfterSessions .set (this .configuredSessionCount > 0 );
158
161
this .sessionCount .set (drainAfterSessionCount );
159
162
this .cdpEnabled = cdpEnabled ;
163
+ this .bidiEnabled = bidiEnabled ;
160
164
161
165
this .healthCheck = healthCheck == null ?
162
166
() -> {
@@ -390,6 +394,7 @@ public Either<WebDriverException, CreateSessionResponse> newSession(CreateSessio
390
394
session ,
391
395
externalUri ,
392
396
slotToUse .isSupportingCdp (),
397
+ slotToUse .isSupportingBiDi (),
393
398
sessionRequest .getDesiredCapabilities ());
394
399
395
400
String sessionCreatedMessage = "Session created by the Node" ;
@@ -427,6 +432,7 @@ public Session getSession(SessionId id) throws NoSuchSessionException {
427
432
slot .getSession (),
428
433
externalUri ,
429
434
slot .isSupportingCdp (),
435
+ slot .isSupportingBiDi (),
430
436
slot .getSession ().getCapabilities ());
431
437
}
432
438
@@ -515,8 +521,11 @@ private void stopAllSessions() {
515
521
}
516
522
}
517
523
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 ) {
520
529
// We merge the session request capabilities and the session ones to keep the values sent
521
530
// by the user in the session information
522
531
Capabilities toUse = ImmutableCapabilities
@@ -535,6 +544,21 @@ private Session createExternalSession(ActiveSession other, URI externalUri,
535
544
}
536
545
});
537
546
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 );
538
562
}
539
563
540
564
// If enabled, set the VNC endpoint for live view
@@ -665,6 +689,7 @@ public static class Builder {
665
689
private int maxSessions = NodeOptions .DEFAULT_MAX_SESSIONS ;
666
690
private int drainAfterSessionCount = NodeOptions .DEFAULT_DRAIN_AFTER_SESSION_COUNT ;
667
691
private boolean cdpEnabled = NodeOptions .DEFAULT_ENABLE_CDP ;
692
+ private boolean bidiEnabled = NodeOptions .DEFAULT_ENABLE_BIDI ;
668
693
private Ticker ticker = Ticker .systemTicker ();
669
694
private Duration sessionTimeout = Duration .ofSeconds (NodeOptions .DEFAULT_SESSION_TIMEOUT );
670
695
private HealthCheck healthCheck ;
@@ -708,6 +733,11 @@ public Builder enableCdp(boolean cdpEnabled) {
708
733
return this ;
709
734
}
710
735
736
+ public Builder enableBiDi (boolean bidiEnabled ) {
737
+ this .bidiEnabled = bidiEnabled ;
738
+ return this ;
739
+ }
740
+
711
741
public Builder sessionTimeout (Duration timeout ) {
712
742
sessionTimeout = timeout ;
713
743
return this ;
@@ -728,6 +758,7 @@ public LocalNode build() {
728
758
maxSessions ,
729
759
drainAfterSessionCount ,
730
760
cdpEnabled ,
761
+ bidiEnabled ,
731
762
ticker ,
732
763
sessionTimeout ,
733
764
heartbeatPeriod ,
0 commit comments