{"record":{"id":"6126a7b8a7128db7","repo":"NanmiCoder/MediaCrawler","slug":"cdp-connection-failed","errorCode":null,"errorMessage":"CDP connection failed","messagePattern":"CDP connection failed","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"tools/cdp_browser.py","lineNumber":354,"sourceCode":"                    utils.logger.info(\n                        f\"[CDPBrowserManager] Connecting to existing browser via discovered CDP: {ws_url}\"\n                    )\n                    self.browser = await playwright.chromium.connect_over_cdp(\n                        ws_url, timeout=config.BROWSER_LAUNCH_TIMEOUT * 1000\n                    )\n            else:\n                # For launched browser, get WebSocket URL first\n                ws_url = await self._get_browser_websocket_url(self.debug_port)\n                utils.logger.info(f\"[CDPBrowserManager] Connecting to browser via CDP: {ws_url}\")\n                self.browser = await playwright.chromium.connect_over_cdp(ws_url)\n\n            if self.browser.is_connected():\n                utils.logger.info(\"[CDPBrowserManager] Successfully connected to browser\")\n                utils.logger.info(\n                    f\"[CDPBrowserManager] Browser contexts count: {len(self.browser.contexts)}\"\n                )\n            else:\n                raise RuntimeError(\"CDP connection failed\")\n\n        except Exception as e:\n            utils.logger.error(f\"[CDPBrowserManager] CDP connection failed: {e}\")\n            raise\n\n    async def _create_browser_context(\n        self, playwright_proxy: Optional[Dict] = None, user_agent: Optional[str] = None\n    ) -> BrowserContext:\n        \"\"\"\n        Create or get browser context\n        \"\"\"\n        if not self.browser:\n            raise RuntimeError(\"Browser not connected\")\n\n        # Get existing context or create new context\n        contexts = self.browser.contexts\n\n        if contexts:","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/NanmiCoder/MediaCrawler/blob/d6f7c5bb906b6dac40ddf343ef9e26438a3de092/tools/cdp_browser.py#L336-L372","documentation":"Error \"CDP connection failed\" thrown in NanmiCoder/MediaCrawler.","triggerScenarios":"Thrown at tools/cdp_browser.py:354 when the library encounters an invalid state.","commonSituations":"playwright.chromium.connect_over_cdp returned but browser.is_connected() is False, or the connection dropped immediately. Occurs when the WebSocket URL is stale, the browser rejected the connection (confirmation dialog not accepted in Chrome 136+), the browser crashed during launch, or BROWSER_LAUNCH_TIMEOUT is too short. Defensive fix: retry the connection after prompting the user to accept the browser confirmation dialog, and validate the browser process before connecting.","solutions":["Ensure the browser process is still alive and did not exit after launch; check logs for a startup crash.","Verify config.CDP_DEBUG_PORT matches the port the browser is listening on (check chrome://inspect/#remote-debugging or the browser launch output).","Increase config.BROWSER_LAUNCH_TIMEOUT if the browser is slow to start on your system.","If connecting to an existing browser on Chrome 136+, accept the confirmation dialog shown in the browser window, then retry."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d6f7c5bb906b6dac40ddf343ef9e26438a3de092","analyzedAt":"2026-08-15T01:39:07.505Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}