You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR allows the values for WebSocket timeout and wait interval to be set via the ClientConfig class in the selenium.webdriver.remote.client_config module.
The class initializer is also where the default values are stored. Previously the values were set in private attributes in the WebSocketConnection class and not easily configurable by the user.
These settings are used for browser communication via WebSockets for both BiDi and CDP.
example usage:
setting the WebSocket timeout and wait interval on an existing local WebDriver:
The new constructor and attributes for WebSocket timing parameters are untyped; adding explicit types (e.g., url: str, timeout: float, interval: float) would improve readability and tooling support.
Accessing client_config.websocket_timeout/interval assumes client_config is always present; verify code paths where WebDriver may be constructed without a client_config to avoid AttributeError or pass-through of None values.
Updated docstrings switched to "with the driver/server" phrasing; ensure consistency across all properties and confirm Sphinx rendering remains correct after reflows.
"""Gets and Sets the proxy used for communicating with the driver/server."""ignore_certificates=_ClientConfigDescriptor("_ignore_certificates")
"""Gets and Sets the ignore certificate check value."""init_args_for_pool_manager=_ClientConfigDescriptor("_init_args_for_pool_manager")
"""Gets and Sets the ignore certificate check."""timeout=_ClientConfigDescriptor("_timeout")
"""Gets and Sets the timeout (in seconds) used for communicating with the driver/server."""ca_certs=_ClientConfigDescriptor("_ca_certs")
"""Gets and Sets the path to bundle of CA certificates."""username=_ClientConfigDescriptor("_username")
"""Gets and Sets the username used for basic authentication to the remote."""password=_ClientConfigDescriptor("_password")
"""Gets and Sets the password used for basic authentication to the remote."""
Ensure time values are non-negative and reasonable before passing to the WebSocket layer. Clamp or raise if invalid to prevent infinite loops or immediate timeouts.
Why: This is a good suggestion for input validation, as user-configurable timeout and interval values could be negative, leading to incorrect behavior in the wait loop.
Medium
Learned best practice
✅ Validate WebSocket constructor inputsSuggestion Impact:The commit added constructor parameter validation for timeout and interval (type checks and positivity), raising errors when invalid, aligning with the suggestion’s intent. It did not validate url nor cast to float, and used WebDriverException instead of ValueError.
code diff:
+ if not isinstance(timeout, (int, float)) or timeout < 0:+ raise WebDriverException("timeout must be a positive number")+ if not isinstance(interval, (int, float)) or timeout < 0:+ raise WebDriverException("interval must be a positive number")+
self.url = url
self.response_wait_timeout = timeout
self.response_wait_interval = interval
Validate the constructor parameters to ensure they are present and of the expected types/ranges. Default or raise clear errors for invalid values to prevent subtle runtime issues.
class WebSocketConnection:
_max_log_message_size = 9999
def __init__(self, url, timeout, interval):
+ if not url:+ raise ValueError("WebSocket URL must be provided")+ if timeout is None or timeout <= 0:+ raise ValueError("timeout must be a positive number")+ if interval is None or interval <= 0:+ raise ValueError("interval must be a positive number")+
self.callbacks = {}
self.session_id = None
self.url = url
- self.response_wait_timeout = timeout- self.response_wait_interval = interval+ self.response_wait_timeout = float(timeout)+ self.response_wait_interval = float(interval)
[Suggestion processed]
Suggestion importance[1-10]: 6
__
Why:
Relevant best practice - Add null checks and validation for parameters and variables before using them to prevent runtime errors.
Low
Possible issue
Handle missing client configuration
Guard against client_config being None to avoid attribute access errors. Provide sensible fallbacks when not configured.
Why: The suggestion to use getattr provides a minor robustness improvement, but self.client_config is unlikely to be None in normal operation, making this a very low-impact change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
🔗 Related Issues
#16270
💥 What does this PR do?
This PR allows the values for WebSocket timeout and wait interval to be set via the
ClientConfigclass in theselenium.webdriver.remote.client_configmodule.The class initializer is also where the default values are stored. Previously the values were set in private attributes in the
WebSocketConnectionclass and not easily configurable by the user.These settings are used for browser communication via WebSockets for both BiDi and CDP.
example usage:
setting the WebSocket timeout and wait interval on an existing local WebDriver:
starting a remote WebDriver using a custom
ClientConfigthat sets the WebSocket timeout and wait interval:🔗 Related Issues
Fixes #16260
🔧 Implementation Notes
This follows the implementation discussed in the 08/21/2025 Selenium TLC call.
🔄 Types of changes
PR Type
Enhancement
Description
Add WebSocket timeout and interval configuration to
ClientConfigUpdate
WebSocketConnectionto accept configurable timeout/interval parametersEnable WebSocket settings for both BiDi and CDP communication
Minor documentation formatting improvements
Diagram Walkthrough
File Walkthrough
client_config.py
Add WebSocket configuration propertiespy/selenium/webdriver/remote/client_config.py
websocket_timeoutandwebsocket_intervalproperties withdescriptors
defaults
webdriver.py
Pass WebSocket config to connectionspy/selenium/webdriver/remote/webdriver.py
start_devtools()to pass WebSocket config fromclient_config_start_bidi()to pass WebSocket config fromclient_configwebsocket_connection.py
Accept configurable timeout and intervalpy/selenium/webdriver/remote/websocket_connection.py