BigPizzaV3/CodexPlusPlus · error · anyhow::Error

CDP WebSocket port does not match debug port

Error message

CDP WebSocket port {port} does not match debug port {expected_port}

What it means

Thrown by `validate_cdp_websocket_url` when the URL's explicit port differs from the debug port the caller expects. This catches stale or mismatched endpoints, e.g. after the browser restarted on a different `--remote-debugging-port`.

Solutions

  1. Re-fetch the current webSocketDebuggerUrl from `http://127.0.0.1:<expected_port>/json/version` so the port matches
  2. Update the expected_port argument to the port the browser is actually using
  3. Correct any config/env where the port was changed for the browser but not for the library

Example fix

// before
validate_cdp_websocket_url("ws://127.0.0.1:9222/devtools/browser/ABC", 9223)?;
// after
validate_cdp_websocket_url("ws://127.0.0.1:9222/devtools/browser/ABC", 9222)?;
Defensive patterns

Strategy: validation

Validate before calling

fn ws_port_matches(url: &str, expected: u16) -> bool {
    reqwest::Url::parse(url).map(|u| u.port() == Some(expected)).unwrap_or(false)
}

Prevention

When it happens

Trigger: Calling `validate_cdp_websocket_url(url, expected_port)` where `url.port() != expected_port`, or the URL omits the port (which first raises 'must include an explicit port').

Common situations: Cached webSocketDebuggerUrl from a previous browser session on another port, multiple Chrome instances on different ports, or a config file with a stale `debug_port`.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/b9e5d6f9f1f0bda4. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/cdp.rs:231

    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) {
            return Ok(target.clone());
        }
    }

    if let Some(target) = first_page {
        return Ok(target.clone());

View on GitHub (pinned to b1ed92e5e4)