Get browser WebSocket connection URL
(self, debug_port: int)
| 286 | ) |
| 287 | |
| 288 | async def _get_browser_websocket_url(self, debug_port: int) -> str: |
| 289 | """ |
| 290 | Get browser WebSocket connection URL |
| 291 | """ |
| 292 | try: |
| 293 | async with httpx.AsyncClient() as client: |
| 294 | response = await client.get( |
| 295 | f"http://localhost:{debug_port}/json/version", timeout=10 |
| 296 | ) |
| 297 | if response.status_code == 200: |
| 298 | data = response.json() |
| 299 | ws_url = data.get("webSocketDebuggerUrl") |
| 300 | if ws_url: |
| 301 | utils.logger.info( |
| 302 | f"[CDPBrowserManager] Got browser WebSocket URL: {ws_url}" |
| 303 | ) |
| 304 | return ws_url |
| 305 | else: |
| 306 | raise RuntimeError("webSocketDebuggerUrl not found") |
| 307 | else: |
| 308 | raise RuntimeError(f"HTTP {response.status_code}: {response.text}") |
| 309 | except Exception as e: |
| 310 | utils.logger.error(f"[CDPBrowserManager] Failed to get WebSocket URL: {e}") |
| 311 | raise |
| 312 | |
| 313 | async def _connect_via_cdp(self, playwright: Playwright): |
| 314 | """ |