{"record":{"id":"7e4613d5f60f2276","repo":"xtekky/gpt4free","slug":"install-websocket-client-package-pip-install-we","errorCode":null,"errorMessage":"Install \"websocket-client\" package: pip install websocket-client","messagePattern":"Install \"websocket-client\" package: pip install websocket-client","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"g4f/requests/cdp.py","lineNumber":752,"sourceCode":"                    target = json.loads(response.read().decode(\"utf-8\"))\n                    ws_url = target.get(\"webSocketDebuggerUrl\")\n                    self.target_id = target.get(\"id\")\n                    if ws_url:\n                        break\n            except Exception:\n                time.sleep(0.5)\n\n        if not ws_url:\n            raise RuntimeError(f\"Failed to create new tab target on port {self.port}\")\n\n        self._connect(ws_url)\n\n    def _connect(self, ws_url: str):\n        \"\"\"Connect via WebSocket to the target.\"\"\"\n        try:\n            from websocket import create_connection\n        except ImportError:\n            raise ImportError(\n                'Install \"websocket-client\" package: pip install websocket-client'\n            )\n\n        self.ws = create_connection(ws_url)\n        self.ws.settimeout(60)  # Prevent infinite hang if Chrome crashes mid-call\n\n        # Enable essential CDP domains\n        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))","sourceCodeStart":734,"sourceCodeEnd":770,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/requests/cdp.py#L734-L770","documentation":"Raised by SyncCDPSession._connect() in g4f/requests/cdp.py when `from websocket import create_connection` fails — the synchronous CDP client deliberately uses the websocket-client package (not aiohttp), and it is an optional dependency. The ImportError surfaces with the exact pip command needed.","triggerScenarios":"Using SyncCDPSession (or a provider that internally uses it, e.g. Turnstile solvers) in an environment where websocket-client is not installed. The tab target was already created successfully, so the browser side is fine — only the Python client library is missing.","commonSituations":"Installing only the async CDP deps (aiohttp) but using the sync client; minimal dependency installs; websocket-client uninstalled as 'unused' by a dependency cleaner.","solutions":["pip install websocket-client (exact command in the message), then retry.","Verify: python -c \"from websocket import create_connection\".","Alternatively use the async CDPSession which depends on aiohttp instead."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"def has_sync_cdp() -> bool:\n    try:\n        from websocket import create_connection  # noqa: F401\n        return True\n    except ImportError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    session = SyncCDPSession(port=9222); session.start_chrome()\nexcept ImportError as e:\n    raise SystemExit(str(e))  # prints the exact pip install command","preventionTips":["Include websocket-client in requirements when using SyncCDPSession.","Detect it at startup rather than mid-request.","Remember async CDPSession uses aiohttp instead — pick deps to match the client used."],"tags":["missing-dependency","websocket-client","cdp","sync","import-error"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}