{"record":{"id":"f7ff4ffc7ba8988e","repo":"xtekky/gpt4free","slug":"cdp-error-in-method-response-error","errorCode":null,"errorMessage":"CDP error in {method}: {response['error']}","messagePattern":"CDP error in (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/requests/cdp.py","lineNumber":778,"sourceCode":"        self.call(\"Page.enable\")\n        self.call(\"DOM.enable\")\n        self.call(\"Runtime.enable\")\n        self.call(\"Network.enable\")\n        self.call(\"Emulation.setFocusEmulationEnabled\", enabled=True)\n\n    def call(self, method: str, **params) -> dict:\n        \"\"\"Send a CDP command and block until the matching response arrives, logging events.\"\"\"\n        self.id_counter += 1\n        payload = {\"id\": self.id_counter, \"method\": method, \"params\": params}\n        self.ws.send(json.dumps(payload))\n\n        # Blocking loop with a 60s socket timeout — won't hang forever if browser exits\n        while True:\n            response = json.loads(self.ws.recv())\n            if \"id\" in response:\n                if response.get(\"id\") == self.id_counter:\n                    if \"error\" in response:\n                        raise RuntimeError(\n                            f\"CDP error in {method}: {response['error']}\"\n                        )\n                    return response.get(\"result\", {})\n            else:\n                # Event\n                event_method = response.get(\"method\")\n                event_params = response.get(\"params\", {})\n                if event_method == \"Network.requestWillBeSent\":\n                    self.network_requests.append(event_params)\n                elif event_method == \"Network.responseReceived\":\n                    self.network_responses.append(event_params)\n\n    def evaluate_js(self, expression: str) -> Any:\n        \"\"\"Execute JS on the page and return the primitive result value.\"\"\"\n        res = self.call(\"Runtime.evaluate\", expression=expression, returnByValue=True)\n        return res.get(\"result\", {}).get(\"value\")\n\n    def get_cookies(self) -> dict:","sourceCodeStart":760,"sourceCodeEnd":796,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/requests/cdp.py#L760-L796","documentation":"Raised by SyncCDPSession.call() in g4f/requests/cdp.py when the browser answered a CDP command with a protocol-level error object ({'error': ...}) instead of a result. This is Chrome DevTools Protocol reporting that the command itself was rejected — invalid parameters, wrong target state, or an unknown/disabled domain — surfaced verbatim by g4f as RuntimeError.","triggerScenarios":"Calling a method of a domain that was never enabled (e.g. Network.getCookies before Network.enable); passing invalid params (bad targetId, malformed expression); calling Page.* on a destroyed target; using a method name not supported by the installed Chrome version.","commonSituations":"Version skew between the client's assumed protocol and an older/newer Chrome; races where the tab navigated or closed between getting a handle and using it; copy-pasted CDP snippets with wrong parameter names.","solutions":["Read the error text embedded in the message — CDP errors (e.g. 'Invalid parameters', 'Not attached to target') name the exact problem.","Enable the required domain first (Page.enable, Network.enable, Runtime.enable...) before its methods.","Re-fetch volatile ids (targetId, requestId) immediately before use rather than caching them.","Match method/params against the Chrome version actually installed; update Chrome or the call accordingly."],"exampleFix":"// before\nsession.call(\"Network.getCookies\", urls=[\"https://x.com\"])  # before Network.enable\n\n// after\nsession.call(\"Network.enable\")\ncookies = session.call(\"Network.getCookies\", urls=[\"https://x.com\"])","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = session.call(method, **params)\nexcept RuntimeError as e:\n    if \"CDP error\" in str(e):\n        log.error(f\"Protocol rejected {method}: {e}\")  # inspect embedded error text\n        raise CommandRejected(method) from e\n    raise","preventionTips":["Enable every CDP domain you call into (Page/Network/Runtime/DOM).","Never cache volatile ids (targetId/requestId) across navigations.","Validate params against the protocol schema for your installed Chrome version."],"tags":["cdp","protocol-error","chrome","api-misuse"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}