{"record":{"id":"49c1eb8b6f8bd814","repo":"SeleniumHQ/selenium","slug":"timed-out-waiting-for-response-to-bidi-command-cu","errorCode":null,"errorMessage":"Timed out waiting for response to BiDi command {current_id}","messagePattern":"Timed out waiting for response to BiDi command (.+?)","errorType":"exception","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/websocket_connection.py","lineNumber":133,"sourceCode":"        self._started = False\n        self._ws = None\n\n    def execute(self, command):\n        with self._id_lock:\n            self._id += 1\n            current_id = self._id\n        payload = self._serialize_command(command)\n        payload[\"id\"] = current_id\n        if self.session_id:\n            payload[\"sessionId\"] = self.session_id\n\n        data = json.dumps(payload, cls=_BiDiEncoder)\n        logger.debug(f\"-> {data}\"[: self._max_log_message_size])\n        self._ws.send(data)\n\n        self._wait_until(lambda: current_id in self._messages)\n        if current_id not in self._messages:\n            raise WebDriverException(f\"Timed out waiting for response to BiDi command {current_id}\")\n        response = self._messages.pop(current_id)\n\n        if \"error\" in response:\n            error = response[\"error\"]\n            if \"message\" in response:\n                error_msg = f\"{error}: {response['message']}\"\n                raise WebDriverException(error_msg)\n            else:\n                raise WebDriverException(error)\n        else:\n            result = response[\"result\"]\n            return self._deserialize_result(result, command)\n\n    def add_callback(self, event, callback):\n        event_name = event.event_class\n        if event_name not in self.callbacks:\n            self.callbacks[event_name] = []\n","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/websocket_connection.py#L115-L151","documentation":"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`.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nconn = WebSocketConnection(url, timeout=5, interval=0.1)\n\n# after\nconn = WebSocketConnection(url, timeout=30, interval=0.1)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = conn.execute(cmd)\nexcept WebDriverException as e:\n    if \"Timed out waiting for response to BiDi command\" in str(e):\n        # optional: verify socket liveness, then retry once with backoff\n        result = retry_bidi(conn, cmd)\n    else:\n        raise","preventionTips":["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."],"tags":["bidi","timeout","network","websocket"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}