SeleniumHQ/selenium · error · WebDriverException
Timed out waiting for response to BiDi command {current_id}
Error message
Timed out waiting for response to BiDi command {current_id} What it means
Raised after `_wait_until(lambda: current_id in self._messages)` elapses without the BiDi response (or error) for a command id arriving. The connection successfully sent the command over the websocket, but no matching response landed in `self._messages` within `response_wait_timeout`.
Source
Thrown at py/selenium/webdriver/remote/websocket_connection.py:133
self._started = False
self._ws = None
def execute(self, command):
with self._id_lock:
self._id += 1
current_id = self._id
payload = self._serialize_command(command)
payload["id"] = current_id
if self.session_id:
payload["sessionId"] = self.session_id
data = json.dumps(payload, cls=_BiDiEncoder)
logger.debug(f"-> {data}"[: self._max_log_message_size])
self._ws.send(data)
self._wait_until(lambda: current_id in self._messages)
if current_id not in self._messages:
raise WebDriverException(f"Timed out waiting for response to BiDi command {current_id}")
response = self._messages.pop(current_id)
if "error" in response:
error = response["error"]
if "message" in response:
error_msg = f"{error}: {response['message']}"
raise WebDriverException(error_msg)
else:
raise WebDriverException(error)
else:
result = response["result"]
return self._deserialize_result(result, command)
def add_callback(self, event, callback):
event_name = event.event_class
if event_name not in self.callbacks:
self.callbacks[event_name] = []
View on GitHub (pinned to aa36b38e69)
Solutions
- Increase the `timeout` (response_wait_timeout) passed to WebSocketConnection.
- Confirm the websocket is still open (watch on_error/on_close) before retrying.
- Retry the BiDi command with backoff; recreate the session if the connection was reset.
- Check the browser/driver logs for the unhandled command id.
Example fix
# before conn = WebSocketConnection(url, timeout=5, interval=0.1) # after conn = WebSocketConnection(url, timeout=30, interval=0.1)
Defensive patterns
Strategy: retry
Try / catch
try:
result = conn.execute(cmd)
except WebDriverException as e:
if "Timed out waiting for response to BiDi command" in str(e):
# optional: verify socket liveness, then retry once with backoff
result = retry_bidi(conn, cmd)
else:
raise Prevention
- Size response_wait_timeout to your slowest expected BiDi operation.
- Monitor websocket on_error/on_close so a dead link is detected before sending.
- Retry transient timeouts but recreate the connection if the link is down.
When it happens
Trigger: Calling any BiDi command (e.g. browsingContext.navigate, script.callFunction) when the remote end hangs, the websocket silently dropped, a slow operation exceeds response_wait_timeout, or the response arrived but was routed under a different id.
Common situations: Network instability or proxy throttling, a remote BiDi implementation that stalls, a timeout set too low for heavy pages, or a navigation/reset that tears down the BiDi session mid-command.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Pattern must be an instance of UrlPattern. Received: '${patt
- Pattern must be an instance of UrlPattern. Received:'${patte
- Pattern must be an instance of String. Received:'${pattern}'
- BiDi connection is closed
- BiDi connection is not open
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/49c1eb8b6f8bd814.
Report an issue: GitHub.