Skip to content

[java] Add web socket timeout for java binding#16410

Closed
iampopovich wants to merge 9 commits intoSeleniumHQ:trunkfrom
iampopovich:feature/ft-16248-websocket-timeout
Closed

[java] Add web socket timeout for java binding#16410
iampopovich wants to merge 9 commits intoSeleniumHQ:trunkfrom
iampopovich:feature/ft-16248-websocket-timeout

Conversation

@iampopovich
Copy link
Copy Markdown
Contributor

@iampopovich iampopovich commented Oct 11, 2025

User description

🔗 Related Issues

fixes #16270
relates #13190

💥 What does this PR do?

This pull request adds support for configuring WebSocket timeout and interval settings for BiDi (Bidirectional) connections in both Chromium and Firefox drivers. It introduces new options in ChromiumOptions and FirefoxOptions to allow users to customize these settings, and propagates these configurations through the driver and HTTP client layers. The changes also ensure these settings are merged and exported as capabilities, making them available throughout the driver lifecycle.

🔧 Implementation Notes

WebSocket Timeout and Interval Configuration Support

  • Added webSocketTimeout and webSocketInterval fields, along with corresponding setter and getter methods, to both ChromiumOptions and FirefoxOptions, allowing users to customize WebSocket communication timing. These are also included in the set of extra capability names and exported as capabilities (se:webSocketTimeout and se:webSocketInterval).

  • Updated the constructors of ChromiumDriver and FirefoxDriver to extract the new WebSocket timeout and interval capabilities and pass them to the BiDi connection logic, ensuring the driver uses the configured values.

  • Modified the createBiDi methods in both drivers to accept and use the WebSocket timeout and interval values when creating the WebSocket client configuration.

HTTP Client Configuration Enhancements

  • Extended ClientConfig to support webSocketTimeout and webSocketInterval fields, with associated builder methods and propagation through all configuration methods. Updated default values and ensured these settings are applied when constructing HTTP clients for WebSocket communication.

Other Minor Updates

  • Added necessary imports for Duration in relevant files. [

💡 Additional Considerations

🔄 Types of changes

  • New feature (non-breaking change which adds functionality and tests!)

PR Type

Enhancement


Description

  • Add WebSocket timeout and interval configuration support for BiDi connections in Java bindings

  • Extend ChromiumOptions and FirefoxOptions with WebSocket timing setters/getters and capability export

  • Propagate WebSocket configuration through driver constructors and HTTP client layers

  • Update ClientConfig and JdkHttpClient to support and apply WebSocket timeout/interval settings


Diagram Walkthrough

flowchart LR
  Options["ChromiumOptions/FirefoxOptions"] -- "WebSocket config" --> Driver["ChromiumDriver/FirefoxDriver"]
  Driver -- "Extract capabilities" --> BiDi["BiDi Connection"]
  BiDi -- "Apply settings" --> ClientConfig["ClientConfig"]
  ClientConfig -- "Configure client" --> JdkHttpClient["JdkHttpClient"]
Loading

File Walkthrough

Relevant files
Enhancement
ChromiumDriver.java
Extract and apply WebSocket configuration in ChromiumDriver

java/src/org/openqa/selenium/chromium/ChromiumDriver.java

  • Extract WebSocket timeout and interval from capabilities with default
    values
  • Pass WebSocket configuration to createBiDi method
  • Update BiDi creation to use configured timeout and interval in
    ClientConfig
+21/-3   
ChromiumOptions.java
Add WebSocket configuration fields and capabilities to ChromiumOptions

java/src/org/openqa/selenium/chromium/ChromiumOptions.java

  • Add webSocketTimeout and webSocketInterval fields with default values
  • Implement setter/getter methods for WebSocket timing configuration
  • Export WebSocket settings as se:webSocketTimeout and
    se:webSocketInterval capabilities
  • Merge WebSocket configuration in mergeInPlace method
+65/-1   
FirefoxDriver.java
Extract and apply WebSocket configuration in FirefoxDriver

java/src/org/openqa/selenium/firefox/FirefoxDriver.java

  • Extract WebSocket timeout and interval from capabilities with defaults
  • Pass WebSocket configuration to createBiDi method
  • Configure ClientConfig with WebSocket timeout and interval for BiDi
    connection
+21/-3   
FirefoxOptions.java
Add WebSocket configuration fields and capabilities to FirefoxOptions

java/src/org/openqa/selenium/firefox/FirefoxOptions.java

  • Add webSocketTimeout and webSocketInterval fields with default values
  • Implement setter/getter methods for WebSocket timing configuration
  • Export WebSocket settings as capabilities in getExtraCapability
  • Add WebSocket capability names to getExtraCapabilityNames
+51/-0   
ClientConfig.java
Extend ClientConfig with WebSocket timeout and interval support

java/src/org/openqa/selenium/remote/http/ClientConfig.java

  • Add webSocketTimeout and webSocketInterval fields to configuration
  • Implement builder methods for WebSocket timeout and interval
  • Set default values from system properties or hardcoded defaults
  • Propagate WebSocket settings through all configuration methods
+68/-0   
JdkHttpClient.java
Apply WebSocket timeout configuration in JdkHttpClient     

java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java

  • Add webSocketTimeout and webSocketInterval fields from ClientConfig
  • Apply webSocketTimeout instead of readTimeout for WebSocket operations
  • Use configured timeout for WebSocket connection establishment and
    message sending
+6/-2     

@selenium-ci selenium-ci added the C-java Java Bindings label Oct 11, 2025
@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Oct 12, 2025

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🔴
Timeout unit mismatch

Description: Inconsistent unit handling for capability 'se:webSocketTimeout': ChromiumDriver treats it
as seconds while FirefoxDriver treats it as milliseconds, which can cause unexpectedly
long or short timeouts and impact stability.
FirefoxDriver.java [164-167]

Referred Code
Object timeoutCapability = capabilities.getCapability("se:webSocketTimeout");
if (timeoutCapability instanceof Number) {
  webSocketTimeout = Duration.ofMillis(((Number) timeoutCapability).longValue());
}
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
No custom compliance provided

Follow the guide to enable custom compliance check.

  • Update
Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Oct 12, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Unify timeout and interval units
Suggestion Impact:ChromiumOptions was changed to export `se:webSocketTimeout` in milliseconds (`toMillis()`) instead of seconds (`toSeconds()`), aligning it with FirefoxOptions’ existing millisecond behavior. The diff does not show corresponding driver-side parsing changes, so the implementation appears partial (options-side only).

code diff:

     // Handle WebSocket configuration capabilities
     if ("se:webSocketTimeout".equals(capabilityName)) {
-      return webSocketTimeout.toSeconds();
+      return webSocketTimeout.toMillis();
     }
     if ("se:webSocketInterval".equals(capabilityName)) {
       return webSocketInterval.toMillis();

Standardize the units used for WebSocket timeout and interval values across all
classes. Currently, ChromiumOptions exports timeout in seconds while
FirefoxOptions uses milliseconds, creating an inconsistency that should be
resolved by using a single unit like milliseconds everywhere.

Examples:

java/src/org/openqa/selenium/chromium/ChromiumOptions.java [280]
      return webSocketTimeout.toSeconds();
java/src/org/openqa/selenium/firefox/FirefoxOptions.java [330]
      return webSocketTimeout.toMillis();

Solution Walkthrough:

Before:

// In ChromiumOptions.java
protected Object getExtraCapability(String capabilityName) {
  if ("se:webSocketTimeout".equals(capabilityName)) {
    return webSocketTimeout.toSeconds(); // Exports as seconds
  }
  // ...
}

// In FirefoxOptions.java
protected Object getExtraCapability(String capabilityName) {
  if ("se:webSocketTimeout".equals(capabilityName)) {
    return webSocketTimeout.toMillis(); // Exports as milliseconds
  }
  // ...
}

// In ChromiumDriver.java
Object timeoutCapability = ...getCapability("se:webSocketTimeout");
webSocketTimeout = Duration.ofSeconds(((Number) timeoutCapability).longValue()); // Interprets as seconds

// In FirefoxDriver.java
Object timeoutCapability = ...getCapability("se:webSocketTimeout");
webSocketTimeout = Duration.ofMillis(((Number) timeoutCapability).longValue()); // Interprets as milliseconds

After:

// In ChromiumOptions.java
protected Object getExtraCapability(String capabilityName) {
  if ("se:webSocketTimeout".equals(capabilityName)) {
    return webSocketTimeout.toMillis(); // Exports as milliseconds
  }
  // ...
}

// In FirefoxOptions.java
protected Object getExtraCapability(String capabilityName) {
  if ("se:webSocketTimeout".equals(capabilityName)) {
    return webSocketTimeout.toMillis(); // Exports as milliseconds
  }
  // ...
}

// In ChromiumDriver.java
Object timeoutCapability = ...getCapability("se:webSocketTimeout");
webSocketTimeout = Duration.ofMillis(((Number) timeoutCapability).longValue()); // Interprets as milliseconds

// In FirefoxDriver.java
Object timeoutCapability = ...getCapability("se:webSocketTimeout");
webSocketTimeout = Duration.ofMillis(((Number) timeoutCapability).longValue()); // Interprets as milliseconds
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical design flaw where ChromiumOptions and FirefoxOptions export the same capability (se:webSocketTimeout) with different units (seconds vs. milliseconds), leading to inconsistent behavior and potential bugs.

High
Possible issue
Ensure consistent timeout unit across drivers
Suggestion Impact:The commit modified the same WebSocket timeout/interval configuration area, but instead of changing milliseconds to seconds, it removed the capability-based Duration parsing entirely and now derives WebSocket settings from the passed ClientConfig when creating the BiDi connection. This eliminates the previous milliseconds-based handling rather than directly switching it to seconds.

code diff:

@@ -157,21 +156,7 @@
               return null;
             });
 
-    // Extract WebSocket configuration from capabilities
-    Duration webSocketTimeout = Duration.ofSeconds(30); // default
-    Duration webSocketInterval = Duration.ofMillis(100); // default
-
-    Object timeoutCapability = capabilities.getCapability("se:webSocketTimeout");
-    if (timeoutCapability instanceof Number) {
-      webSocketTimeout = Duration.ofMillis(((Number) timeoutCapability).longValue());
-    }
-
-    Object intervalCapability = capabilities.getCapability("se:webSocketInterval");
-    if (intervalCapability instanceof Number) {
-      webSocketInterval = Duration.ofMillis(((Number) intervalCapability).longValue());
-    }
-
-    this.biDi = createBiDi(biDiUri, webSocketTimeout, webSocketInterval);
+    this.biDi = createBiDi(biDiUri, clientConfig);
 
     this.capabilities = new ImmutableCapabilities(capabilities);
   }
@@ -255,7 +240,7 @@
     context.setContext(commandContext);
   }
 
-  private Optional<BiDi> createBiDi(Optional<URI> biDiUri, Duration webSocketTimeout, Duration webSocketInterval) {
+  private Optional<BiDi> createBiDi(Optional<URI> biDiUri, ClientConfig clientConfig) {
     if (biDiUri.isEmpty()) {
       return Optional.empty();
     }
@@ -268,10 +253,7 @@
                         + " capability is set."));
 
     HttpClient.Factory clientFactory = HttpClient.Factory.createDefault();
-    ClientConfig wsConfig = ClientConfig.defaultConfig()
-        .baseUri(wsUri)
-        .webSocketTimeout(webSocketTimeout)
-        .webSocketInterval(webSocketInterval);
+    ClientConfig wsConfig = clientConfig.baseUri(wsUri);
     HttpClient wsClient = clientFactory.createClient(wsConfig);

In FirefoxDriver, change the unit for the se:webSocketTimeout capability from
milliseconds to seconds to ensure consistency with ChromiumDriver.

java/src/org/openqa/selenium/firefox/FirefoxDriver.java [164-167]

 Object timeoutCapability = capabilities.getCapability("se:webSocketTimeout");
 if (timeoutCapability instanceof Number) {
-  webSocketTimeout = Duration.ofMillis(((Number) timeoutCapability).longValue());
+  webSocketTimeout = Duration.ofSeconds(((Number) timeoutCapability).longValue());
 }

[Suggestion processed]

Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies an inconsistency in how the se:webSocketTimeout capability is handled between FirefoxDriver (milliseconds) and ChromiumDriver (seconds), and proposes a change to align them, improving framework consistency.

Medium
Export timeout capability in seconds
Suggestion Impact:The commit did not implement exporting the timeout in seconds; instead, it removed the se:webSocketTimeout (and se:webSocketInterval) capabilities entirely from FirefoxOptions, including the fields, extra capability names, and the code that exported them (previously in milliseconds). This changes the behavior in the same area but does not follow the suggested unit-alignment change.

code diff:

-  /**
-   * Sets the WebSocket timeout for BiDi connections.
-   *
-   * @param webSocketTimeout the WebSocket timeout duration
-   * @return A self reference.
-   */
-  public FirefoxOptions setWebSocketTimeout(Duration webSocketTimeout) {
-    this.webSocketTimeout = Require.nonNull("WebSocket timeout", webSocketTimeout);
-    return this;
-  }
-
-  /**
-   * Gets the WebSocket timeout for BiDi connections.
-   *
-   * @return the WebSocket timeout duration
-   */
-  public Duration getWebSocketTimeout() {
-    return webSocketTimeout;
-  }
-
-  /**
-   * Sets the WebSocket interval for BiDi connections.
-   *
-   * @param webSocketInterval the WebSocket interval duration
-   * @return A self reference.
-   */
-  public FirefoxOptions setWebSocketInterval(Duration webSocketInterval) {
-    this.webSocketInterval = Require.nonNull("WebSocket interval", webSocketInterval);
-    return this;
-  }
-
-  /**
-   * Gets the WebSocket interval for BiDi connections.
-   *
-   * @return the WebSocket interval duration
-   */
-  public Duration getWebSocketInterval() {
-    return webSocketInterval;
-  }
-
   @Override
   protected Set<String> getExtraCapabilityNames() {
     Set<String> names = new TreeSet<>();
 
     names.add(FIREFOX_OPTIONS);
-    names.add("se:webSocketTimeout");
-    names.add("se:webSocketInterval");
 
     return Collections.unmodifiableSet(names);
   }
@@ -325,12 +279,6 @@
 
     if (FIREFOX_OPTIONS.equals(capabilityName)) {
       return Collections.unmodifiableMap(firefoxOptions);
-    }
-    if ("se:webSocketTimeout".equals(capabilityName)) {
-      return webSocketTimeout.toMillis();
-    }
-    if ("se:webSocketInterval".equals(capabilityName)) {
-      return webSocketInterval.toMillis();
     }
     return null;
   }

In FirefoxOptions, change the export unit for the se:webSocketTimeout capability
from milliseconds to seconds to align with ChromiumOptions.

java/src/org/openqa/selenium/firefox/FirefoxOptions.java [329-331]

 if ("se:webSocketTimeout".equals(capabilityName)) {
-  return webSocketTimeout.toMillis();
+  return webSocketTimeout.toSeconds();
 }

[Suggestion processed]

Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that FirefoxOptions exports se:webSocketTimeout in milliseconds, which is inconsistent with ChromiumOptions (seconds). Aligning this improves consistency across browser options.

Medium
General
Correct inaccurate Javadoc for interval unit

Correct the Javadoc for setWebSocketInterval and getWebSocketInterval to state
that the interval unit is milliseconds, not seconds.

java/src/org/openqa/selenium/chromium/ChromiumOptions.java [245-263]

 /**
- * Sets the WebSocket response wait interval (in seconds) used for communicating with the browser.
+ * Sets the WebSocket response wait interval (in milliseconds) used for communicating with the browser.
  *
  * @param interval WebSocket response wait interval
  * @return A self reference.
  */
 public T setWebSocketInterval(Duration interval) {
   this.webSocketInterval = Require.nonNull("WebSocket interval", interval);
   return (T) this;
 }
 
 /**
- * Gets the WebSocket response wait interval (in seconds) used for communicating with the browser.
+ * Gets the WebSocket response wait interval (in milliseconds) used for communicating with the browser.
  *
  * @return WebSocket response wait interval
  */
 public Duration getWebSocketInterval() {
   return webSocketInterval;
 }
  • Apply / Chat
Suggestion importance[1-10]: 4

__

Why: The suggestion correctly identifies that the Javadoc for setWebSocketInterval and getWebSocketInterval incorrectly states the unit is seconds when it is milliseconds, and fixing it improves documentation accuracy.

Low
  • Update

@iampopovich
Copy link
Copy Markdown
Contributor Author

based on the test in python implementation i added properties with duration seconds and milliseconds
https://github.com/SeleniumHQ/selenium/pull/16248/files#diff-d7e08eadd4f84a4b0574e9d4a0927715c6d80f85b263485272346d8dc99a6821

def test_default_websocket_settings():
    config = ClientConfig(remote_server_addr="http://localhost:4444")
    assert config.websocket_timeout == 30.0
    assert config.websocket_interval == 0.1

should it be both of milliseconds ?

Copy link
Copy Markdown
Member

@titusfortner titusfortner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep these parameters contained to the client config class. The BiDi spec doesn't manage any timeouts, so we don't need to have options that get sent to the browser, and we don't want the driver juggling this directly.

Check out #13190 where we create a BiDi command executor to manage all of this. I'm not sure how close to ready that PR is I haven't looked at it in a while, but we actually want to pull this code out of the individual drivers.

@cgoldberg
Copy link
Copy Markdown
Member

should it be both of milliseconds ?

In Python, both values are in seconds. (defaults are 30.0 and 0.1)

We need to keep these parameters contained to the client config class

In Python, we have websocket_timeout and websocket_interval attributes on the ClientConfig class. The defaults can be overriden in the contructor. This follows the same design as we already use for setting HTTP timeouts.

Here is an example of instantiating a Remote webdriver with a ClientConfig using custom websocket timeouts:

@diemol
Copy link
Copy Markdown
Member

diemol commented Oct 17, 2025

We need to get the ClientConfig all they way down to the drivers. I would like to avoid this approach.

Copilot AI review requested due to automatic review settings January 3, 2026 16:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for configuring WebSocket timeout and interval settings for BiDi connections in Java bindings. It introduces new configuration options in ChromiumOptions and FirefoxOptions, propagates these settings through driver constructors, and extends the HTTP client infrastructure to support these parameters.

  • Adds webSocketTimeout and webSocketInterval configuration fields with default values (30 seconds and 100 milliseconds respectively) to options classes
  • Extracts and propagates WebSocket configuration from capabilities through driver constructors to BiDi connection setup
  • Extends ClientConfig and JdkHttpClient to support and apply WebSocket timeout settings

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
ChromiumOptions.java Adds WebSocket timeout/interval fields, setters/getters, and capability export with proper merge logic
ChromiumDriver.java Extracts WebSocket configuration from capabilities and passes to BiDi connection creation
FirefoxOptions.java Adds WebSocket timeout/interval fields, setters/getters, and capability export
FirefoxDriver.java Extracts WebSocket configuration from capabilities and passes to BiDi connection creation
ClientConfig.java Extends configuration to support WebSocket timeout/interval with builder pattern methods
JdkHttpClient.java Stores WebSocket configuration and applies timeout to WebSocket operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

/**
* Gets the WebSocket response wait interval (in seconds) used for communicating with the browser.
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states the parameter is "in seconds" but the default value is Duration.ofMillis(100), which is 100 milliseconds, not seconds. The documentation should be corrected to say "used for communicating with the browser" without specifying the unit, or should correctly indicate it accepts a Duration object.

Copilot uses AI. Check for mistakes.
}

/**
* Gets the WebSocket response wait timeout (in seconds) used for communicating with the browser.
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states the parameter is "in seconds" but the default value is Duration.ofSeconds(30), which is correct. However, the getter documentation also says "in seconds" which is misleading since it returns a Duration object. Consider updating the documentation to simply say "WebSocket response wait timeout" without specifying the unit since Duration handles that.

Copilot uses AI. Check for mistakes.
}

/**
* Sets the WebSocket response wait timeout (in seconds) used for communicating with the browser.
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states the parameter is "in seconds" but the default value is Duration.ofSeconds(30), which is correct. However, the getter documentation also says "in seconds" which is misleading since it returns a Duration object. Consider updating the documentation to simply say "WebSocket response wait timeout" without specifying the unit since Duration handles that.

Copilot uses AI. Check for mistakes.
Comment on lines +234 to +272
/**
* Sets the WebSocket response wait timeout (in seconds) used for communicating with the browser.
*
* @param timeout WebSocket response wait timeout
* @return A self reference.
*/
public T setWebSocketTimeout(Duration timeout) {
this.webSocketTimeout = Require.nonNull("WebSocket timeout", timeout);
return (T) this;
}

/**
* Gets the WebSocket response wait timeout (in seconds) used for communicating with the browser.
*
* @return WebSocket response wait timeout
*/
public Duration getWebSocketTimeout() {
return webSocketTimeout;
}

/**
* Sets the WebSocket response wait interval (in seconds) used for communicating with the browser.
*
* @param interval WebSocket response wait interval
* @return A self reference.
*/
public T setWebSocketInterval(Duration interval) {
this.webSocketInterval = Require.nonNull("WebSocket interval", interval);
return (T) this;
}

/**
* Gets the WebSocket response wait interval (in seconds) used for communicating with the browser.
*
* @return WebSocket response wait interval
*/
public Duration getWebSocketInterval() {
return webSocketInterval;
}
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new WebSocket timeout and interval configuration features lack test coverage. Consider adding unit tests to verify: 1) that the setter and getter methods work correctly, 2) that the capabilities are properly exported with the correct keys ("se:webSocketTimeout" and "se:webSocketInterval"), 3) that the values are properly converted to milliseconds, and 4) that the merge behavior works correctly in mergeInPlace.

Copilot uses AI. Check for mistakes.
Comment on lines +270 to +308
/**
* Sets the WebSocket timeout for BiDi connections.
*
* @param webSocketTimeout the WebSocket timeout duration
* @return A self reference.
*/
public FirefoxOptions setWebSocketTimeout(Duration webSocketTimeout) {
this.webSocketTimeout = Require.nonNull("WebSocket timeout", webSocketTimeout);
return this;
}

/**
* Gets the WebSocket timeout for BiDi connections.
*
* @return the WebSocket timeout duration
*/
public Duration getWebSocketTimeout() {
return webSocketTimeout;
}

/**
* Sets the WebSocket interval for BiDi connections.
*
* @param webSocketInterval the WebSocket interval duration
* @return A self reference.
*/
public FirefoxOptions setWebSocketInterval(Duration webSocketInterval) {
this.webSocketInterval = Require.nonNull("WebSocket interval", webSocketInterval);
return this;
}

/**
* Gets the WebSocket interval for BiDi connections.
*
* @return the WebSocket interval duration
*/
public Duration getWebSocketInterval() {
return webSocketInterval;
}
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new WebSocket timeout and interval configuration features lack test coverage. Consider adding unit tests to verify: 1) that the setter and getter methods work correctly, 2) that the capabilities are properly exported with the correct keys ("se:webSocketTimeout" and "se:webSocketInterval"), and 3) that the values are properly converted to milliseconds.

Copilot uses AI. Check for mistakes.
Comment on lines +390 to +395
if (options.webSocketTimeout != null) {
setWebSocketTimeout(options.webSocketTimeout);
}
if (options.webSocketInterval != null) {
setWebSocketInterval(options.webSocketInterval);
}
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null checks for webSocketTimeout and webSocketInterval are unnecessary because these fields are initialized with non-null default values (Duration.ofSeconds(30) and Duration.ofMillis(100)) in the field declarations. These fields can never be null unless explicitly set via reflection. Consider removing these null checks or use Optional.ofNullable() pattern for consistency with the other optional fields in this method.

Suggested change
if (options.webSocketTimeout != null) {
setWebSocketTimeout(options.webSocketTimeout);
}
if (options.webSocketInterval != null) {
setWebSocketInterval(options.webSocketInterval);
}
setWebSocketTimeout(options.webSocketTimeout);
setWebSocketInterval(options.webSocketInterval);

Copilot uses AI. Check for mistakes.
private final Duration readTimeout;
private final Duration connectTimeout;
private final Duration webSocketTimeout;
private final Duration webSocketInterval;
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The webSocketInterval field is stored but never actually used in the WebSocket implementation. According to the related issue #16270, this interval should be used to check for a response to a sent message, but it's not applied anywhere in the WebSocket send logic or connection establishment. Consider implementing the intended behavior or removing this unused field.

Copilot uses AI. Check for mistakes.
}

/**
* Sets the WebSocket response wait interval (in seconds) used for communicating with the browser.
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation states the parameter is "in seconds" but the default value is Duration.ofMillis(100), which is 100 milliseconds, not seconds. The documentation should be corrected to say "used for communicating with the browser" without specifying the unit, or should correctly indicate it accepts a Duration object.

Copilot uses AI. Check for mistakes.
Duration.ofSeconds(
Long.parseLong(System.getProperty("webdriver.httpclient.readTimeout", "180"))),
Duration.ofSeconds(
Long.parseLong(System.getProperty("webdriver.httpclient.webSocketTimeout", "30"))),
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential uncaught 'java.lang.NumberFormatException'.

Copilot uses AI. Check for mistakes.
Duration.ofSeconds(
Long.parseLong(System.getProperty("webdriver.httpclient.webSocketTimeout", "30"))),
Duration.ofMillis(
Long.parseLong(System.getProperty("webdriver.httpclient.webSocketInterval", "100"))),
Copy link

Copilot AI Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential uncaught 'java.lang.NumberFormatException'.

Copilot uses AI. Check for mistakes.
@iampopovich
Copy link
Copy Markdown
Contributor Author

We need to keep these parameters contained to the client config class. The BiDi spec doesn't manage any timeouts, so we don't need to have options that get sent to the browser, and we don't want the driver juggling this directly.

Check out #13190 where we create a BiDi command executor to manage all of this. I'm not sure how close to ready that PR is I haven't looked at it in a while, but we actually want to pull this code out of the individual drivers.

@titusfortner Let's wait for #13190 to be merged into trunk, and then use the BiDi executor in this PR for timeouts.

@asolntsev
Copy link
Copy Markdown
Contributor

What's the status of this PR?
Apparently, PR #13190 will not be merged soon - seems that Puja is not working on it anymore. :(

I created another PR #16796 which is somewhat simpler: it just adds wsTimeout to ClientConfig - and uses a shorter timeout in few tests (which makes these tests much faster!).

Can we maybe merge my PR and then continue with all these bigger historical changes? @iampopovich @titusfortner

@iampopovich
Copy link
Copy Markdown
Contributor Author

@asolntsev I don't mind if we use your changes going forward, as long as they're simpler and already ready. You can close my pull request.

@iampopovich iampopovich closed this Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🚀 Feature]: Allow to configure WebSocket timeouts in ClientConfig

7 participants