{"record":{"id":"2fe567aa1e18e563","repo":"SeleniumHQ/selenium","slug":"error-response-message","errorCode":null,"errorMessage":"{error}: {response['message']}","messagePattern":"\\{error\\}: \\{response\\['message'\\]\\}","errorType":"exception","errorClass":"WebDriverException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/remote/websocket_connection.py","lineNumber":140,"sourceCode":"        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\n        def _callback(params):\n            callback(event.from_json(params))\n\n        self.callbacks[event_name].append(_callback)\n        return id(_callback)\n\n    on = add_callback","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/remote/websocket_connection.py#L122-L158","documentation":"The remote BiDi end returned an error response object carrying both an `error` field (the BiDi-spec error type) and a `message` field (human-readable detail). The library formats them as '{error}: {message}' and re-raises as WebDriverException.","triggerScenarios":"Sending a malformed BiDi command (invalid params), referencing an unknown or already-closed browsing context, an unknown command, or any protocol-level error such as 'invalid argument' / 'no such frame'.","commonSituations":"Using a browsing context handle after it was closed, passing wrong parameter types to a BiDi command, or version skew between the client's command set and the browser's BiDi support.","solutions":["Parse the exception text to extract the BiDi error code before the colon and map it to spec handling.","Validate command parameters (context id, script, etc.) before sending.","Ensure the browser/driver version supports the BiDi command you call.","Re-open the browsing context / session if it was closed."],"exampleFix":"# before\nconn.execute(BrowsingContext.Navigate(context=closed_id, url=u))\n\n# after\nif context_still_open(closed_id):\n    conn.execute(BrowsingContext.Navigate(context=closed_id, url=u))","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = conn.execute(cmd)\nexcept WebDriverException as e:\n    code, _, detail = str(e).partition(\": \")\n    if code == \"no such browsing context\":\n        reopen_and_retry()\n    else:\n        raise","preventionTips":["Inspect the error code portion to branch on known BiDi error types.","Do not reuse context handles across navigations that reset the session."],"tags":["bidi","protocol","error-handling"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}