{"record":{"id":"8242f9e1944e8386","repo":"BigPizzaV3/CodexPlusPlus","slug":"periodic-runtime-evaluate-reported-unavailable-cap","errorCode":null,"errorMessage":"periodic Runtime.evaluate reported unavailable capability","messagePattern":"periodic Runtime\\.evaluate reported unavailable capability","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/bridge.rs","lineNumber":243,"sourceCode":"{\n    let socket = connect_cdp_websocket(websocket_url).await?;\n    let mut session = CdpSession::new(socket);\n    let mut interval = tokio::time::interval(period);\n    loop {\n        interval.tick().await;\n        let Some(expression) = next_expression()? else {\n            return Ok(());\n        };\n        let response = session\n            .send_command(\n                next_message_id(),\n                \"Runtime.evaluate\",\n                runtime_evaluate_params(&expression),\n            )\n            .await?;\n        let response = ensure_runtime_evaluate_succeeded(response)?;\n        if runtime_evaluate_result_is_false(&response) {\n            bail!(\"periodic Runtime.evaluate reported unavailable capability\");\n        }\n    }\n}\n\npub async fn add_script_to_new_documents(\n    websocket_url: &str,\n    script: &str,\n) -> anyhow::Result<Value> {\n    let socket = connect_cdp_websocket(websocket_url).await?;\n    let mut session = CdpSession::new(socket);\n    session\n        .send_command(\n            1,\n            \"Page.addScriptToEvaluateOnNewDocument\",\n            json!({ \"source\": script }),\n        )\n        .await\n}","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/bridge.rs#L225-L261","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the periodic expression being passed as next_expression and evaluate it manually in DevTools to see which condition is false","Ensure add_script_to_new_documents was called so the setup re-runs on every new document","After an app update, refresh the hook/capture logic to match the new internals","Relax or re-arm the probe (re-inject and retry) instead of assuming permanent failure"],"exampleFix":"// before\nrun_periodic_evaluations(ws, period, || Ok(Some(\"return !!window.__cap\".into()))).await?;\n// after (retry a few ticks before failing)\nlet mut misses = 0;\nrun_periodic_evaluations(ws, period, move || {\n    Ok(Some(\"window.__cap ? true : (window.__misses=(window.__misses||0)+1, window.__misses<5)\".into()))\n}).await?;","handlingStrategy":"retry","validationCode":"// probe the capability once before starting the periodic loop\nlet ok = evaluate_script(&ws, \"return !!window.__cap\").await?;\nlet ready = ok.as_bool() == Some(true);\nif !ready { eprintln!(\"capability not present yet; re-inject setup script first\"); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = run_periodic_evaluations(&ws, period, next_expression).await {\n    if e.to_string().contains(\"unavailable capability\") {\n        add_script_to_new_documents(&ws, &setup_script).await?;\n        run_periodic_evaluations(&ws, period, next_expression).await?;\n    } else { return Err(e); }\n}","preventionTips":["Re-inject the setup script on every new document via add_script_to_new_documents","Version-check the target app after updates — the probed internals may have moved","Write probes defensively (typeof guards) and allow a few false ticks before declaring failure"],"tags":["cdp","javascript","capability-probe","runtime-evaluate"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}