BigPizzaV3/CodexPlusPlus · error · anyhow::Error

periodic Runtime.evaluate reported unavailable capability

Error message

periodic Runtime.evaluate reported unavailable capability

What it means

run_periodic_evaluations evaluates a caller-provided expression on a fixed interval and treats a JavaScript result of exactly false as a capability probe failure. If the periodic script (typically a feature-detection/keepalive expression) returns false — meaning the required in-page capability is absent — the loop bails with this error and terminates the periodic session.

Solutions

  1. Inspect the periodic expression being passed as next_expression and evaluate it manually in DevTools to see which condition is false
  2. Ensure add_script_to_new_documents was called so the setup re-runs on every new document
  3. After an app update, refresh the hook/capture logic to match the new internals
  4. Relax or re-arm the probe (re-inject and retry) instead of assuming permanent failure

Example fix

// before
run_periodic_evaluations(ws, period, || Ok(Some("return !!window.__cap".into()))).await?;
// after (retry a few ticks before failing)
let mut misses = 0;
run_periodic_evaluations(ws, period, move || {
    Ok(Some("window.__cap ? true : (window.__misses=(window.__misses||0)+1, window.__misses<5)".into()))
}).await?;
Defensive patterns

Strategy: retry

Validate before calling

// probe the capability once before starting the periodic loop
let ok = evaluate_script(&ws, "return !!window.__cap").await?;
let ready = ok.as_bool() == Some(true);
if !ready { eprintln!("capability not present yet; re-inject setup script first"); }

Try / catch

if let Err(e) = run_periodic_evaluations(&ws, period, next_expression).await {
    if e.to_string().contains("unavailable capability") {
        add_script_to_new_documents(&ws, &setup_script).await?;
        run_periodic_evaluations(&ws, period, next_expression).await?;
    } else { return Err(e); }
}

Prevention

When it happens

Trigger: The injected capability probe script evaluates to false on some tick: the page reloaded/navigated wiping the injected state, the target is on an app version where the hook target (e.g. AppServerRequestClient capture) no longer exists, or the probe's condition (like window.__codexPlusAppServerClientClass) never became truthy.

Common situations: Codex app update changed the internals the probe detects; SPA navigation/reload cleared the captured class before the next tick; the setup script (add_script_to_new_documents) never ran on the current document.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at crates/codex-plus-core/src/bridge.rs:243

{
    let socket = connect_cdp_websocket(websocket_url).await?;
    let mut session = CdpSession::new(socket);
    let mut interval = tokio::time::interval(period);
    loop {
        interval.tick().await;
        let Some(expression) = next_expression()? else {
            return Ok(());
        };
        let response = session
            .send_command(
                next_message_id(),
                "Runtime.evaluate",
                runtime_evaluate_params(&expression),
            )
            .await?;
        let response = ensure_runtime_evaluate_succeeded(response)?;
        if runtime_evaluate_result_is_false(&response) {
            bail!("periodic Runtime.evaluate reported unavailable capability");
        }
    }
}

pub async fn add_script_to_new_documents(
    websocket_url: &str,
    script: &str,
) -> anyhow::Result<Value> {
    let socket = connect_cdp_websocket(websocket_url).await?;
    let mut session = CdpSession::new(socket);
    session
        .send_command(
            1,
            "Page.addScriptToEvaluateOnNewDocument",
            json!({ "source": script }),
        )
        .await
}

View on GitHub (pinned to b1ed92e5e4)