{"record":{"id":"b41e4724692e00af","repo":"Kuberwastaken/claurst","slug":"websocket-connect-to-failed","errorCode":null,"errorMessage":"WebSocket connect to {} failed: {}","messagePattern":"WebSocket connect to (.+?) failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-rust/crates/commands/src/chrome.rs","lineNumber":146,"sourceCode":"            .ok_or_else(|| {\r\n                anyhow::anyhow!(\r\n                    \"No debuggable page found on port {}. \\\r\n                     Make sure Chrome has at least one open tab.\",\r\n                    port\r\n                )\r\n            })?;\r\n\r\n        let tab_url = tabs\r\n            .as_array()\r\n            .and_then(|arr| {\r\n                arr.iter()\r\n                    .find(|t| t[\"type\"] == \"page\")\r\n                    .and_then(|t| t[\"url\"].as_str().map(|s| s.to_string()))\r\n            })\r\n            .unwrap_or_default();\r\n\r\n        let (ws, _) = connect_async(&ws_url).await.map_err(|e| {\r\n            anyhow::anyhow!(\"WebSocket connect to {} failed: {}\", ws_url, e)\r\n        })?;\r\n\r\n        let mut session = ChromeSession { ws, port, tab_url: tab_url.clone() };\r\n        // Enable Page domain so captureScreenshot etc. work.\r\n        cdp_call(&mut session.ws, \"Page.enable\", json!({})).await?;\r\n        // Enable Runtime domain for eval/click/fill.\r\n        cdp_call(&mut session.ws, \"Runtime.enable\", json!({})).await?;\r\n\r\n        store_session(session);\r\n\r\n        Ok(format!(\r\n            \"Connected to Chrome on port {} (tab: {})\",\r\n            port, tab_url\r\n        ))\r\n    }\r\n\r\n    /// Disconnect the current session.\r\n    pub fn disconnect() -> String {\r","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/commands/src/chrome.rs#L128-L164","documentation":"Thrown by `connect` when the tungstenite `connect_async` call to Chrome's webSocketDebuggerUrl fails. The HTTP target lookup succeeded, but establishing the CDP WebSocket handshake did not; the underlying tungstenite error is embedded in the message.","triggerScenarios":"Chrome closed between the /json HTTP query and the WebSocket dial; the ws URL host/port unreachable; proxy or TLS interference; Chrome restarted and the tab (and its debugger URL) is gone; the ws_url from a stale target list no longer accepts connections.","commonSituations":"Race where Chrome is shutting down while connect runs; connecting to a Docker-mapped port where only the HTTP endpoint is forwarded; wrong port collision (another service answering /json-shaped responses).","solutions":["Confirm Chrome is still running and the debug port is alive (`curl http://127.0.0.1:<port>/json/version`).","Re-run `/chrome connect` — the previous ws URL may be stale after a Chrome restart.","Check firewall/proxy settings that could block the WebSocket upgrade on the debug port.","Retry with a fresh port if Chrome was relaunched with a different --remote-debugging-port."],"exampleFix":"// before: stale URL after Chrome restart\nlet (ws, _) = connect_async(&ws_url).await?;\n\n// after: re-fetch target list immediately before dialing\nlet targets = fetch_targets(port).await?;\nlet ws_url = pick_page_ws_url(&targets)?;\nlet (ws, _) = connect_async(&ws_url).await.map_err(|e| anyhow!(\"WebSocket connect to {} failed: {}\", ws_url, e))?;","handlingStrategy":"retry","validationCode":"let alive = reqwest::get(format!(\"http://127.0.0.1:{}/json/version\", port)).await.is_ok();\nif !alive { /* Chrome is down; restart it before connecting */ }","typeGuard":"async fn ws_reachable(ws_url: &str) -> bool {\n    // cheap check: HTTP endpoint on the same port still answers\n    ws_url.parse::<reqwest::Url>().is_ok() && port_probe(ws_url).await\n}","tryCatchPattern":"match connect(port).await {\n    Ok(s) => Ok(s),\n    Err(e) if e.to_string().contains(\"WebSocket connect\") => {\n        tokio::time::sleep(Duration::from_millis(500)).await;\n        connect(port).await // retry once with fresh target list\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Fetch the target list immediately before dialing the WebSocket.","Retry connect once on failure — stale ws URLs are common after Chrome restarts.","Keep Chrome alive for the whole automation session.","Check proxy/firewall rules for the debug port."],"tags":["websocket","chrome","cdp","network","connection"],"backgroundTag":"connection-refused","analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}