BigPizzaV3/CodexPlusPlus · error · anyhow::Error
CDP WebSocket host must be loopback
Error message
CDP WebSocket host must be loopback
What it means
Thrown by `validate_cdp_websocket_url` when the URL's host is not a loopback IP address (or cannot be parsed as an IP at all). The library restricts CDP WebSocket connections to loopback (127.0.0.0/8, ::1) as a security measure so it never connects to remote debug endpoints.
Solutions
- Replace the host with an explicit loopback IP: `127.0.0.1` or `[::1]` (avoid the name `localhost`, which is not an IpAddr literal)
- If the browser runs elsewhere, run a local port forward (e.g. `ssh -L`) so the CDP endpoint appears on loopback
- Never disable the check by pointing at remote IPs; use an SSH tunnel instead
Example fix
// before
validate_cdp_websocket_url("ws://localhost:9222/devtools/browser/ABC", 9222)?;
// after
validate_cdp_websocket_url("ws://127.0.0.1:9222/devtools/browser/ABC", 9222)?; Defensive patterns
Strategy: validation
Validate before calling
fn is_loopback_ws(url: &str) -> bool {
reqwest::Url::parse(url).ok()
.and_then(|u| u.host_str().map(|h| h.to_string()))
.map(|h| h.trim_start_matches('[').trim_end_matches(']').parse::<std::net::IpAddr>().map_or(false, |ip| ip.is_loopback()))
.unwrap_or(false)
} Prevention
- Use 127.0.0.1 or [::1], not the hostname 'localhost'
- Use SSH port forwarding for remote browsers so the endpoint stays on loopback
- Never point CDP at LAN/public IPs — the library blocks it by design
When it happens
Trigger: Passing a URL with a hostname (`localhost` is NOT parsed as an IP here), a public/LAN IP, or a remote machine's debug endpoint into `validate_cdp_websocket_url`.
Common situations: Using `ws://localhost:9222/...` instead of `ws://127.0.0.1:9222/...`, pointing at a container/VM host IP, or remote debugging over the network.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- API 地址须使用 HTTPS,且不含账号、密码、查询参数或片段
- API 地址须使用 HTTPS,且不含账号、密码、查询参数或片段
- CDP WebSocket URL has no host
- CDP WebSocket URL must use ws or wss
- failed to query CDP browser identity on loopback addresses
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/e695ea0d0a382abb.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/cdp.rs:225
}
Ok(targets)
}
pub fn validate_cdp_websocket_url(url: &str, expected_port: u16) -> anyhow::Result<()> {
let parsed = reqwest::Url::parse(url).context("invalid CDP WebSocket URL")?;
if !matches!(parsed.scheme(), "ws" | "wss") {
bail!("CDP WebSocket URL must use ws or wss");
}
let host = parsed
.host_str()
.ok_or_else(|| anyhow::anyhow!("CDP WebSocket URL has no host"))?;
let address = host
.trim_start_matches('[')
.trim_end_matches(']')
.parse::<IpAddr>()
.with_context(|| "CDP WebSocket host must be a loopback IP address")?;
if !address.is_loopback() {
bail!("CDP WebSocket host must be loopback");
}
let port = parsed
.port()
.ok_or_else(|| anyhow::anyhow!("CDP WebSocket URL must include an explicit port"))?;
if port != expected_port {
bail!("CDP WebSocket port {port} does not match debug port {expected_port}");
}
Ok(())
}
pub fn pick_page_target(targets: &[CdpTarget]) -> anyhow::Result<CdpTarget> {
let mut first_page = None;
for target in targets
.iter()
.filter(|target| is_injectable_page_target(target))
{
first_page.get_or_insert(target);
if is_primary_codex_page_target(target) {View on GitHub (pinned to b1ed92e5e4)