{"record":{"id":"33b0e8bac44489ed","repo":"karatelabs/karate","slug":"timeout-waiting-for-frame-context-frameid-will-retry-on","errorCode":null,"errorMessage":"timeout waiting for frame context: frameId={} (will retry on first use)","messagePattern":"timeout waiting for frame context: frameId=(.+?) \\(will retry on first use\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java","lineNumber":2645,"sourceCode":"            try {\n                CdpResponse response = cdp.method(\"Runtime.evaluate\")\n                        .param(\"expression\", \"typeof document !== 'undefined'\")\n                        .param(\"returnByValue\", true)\n                        .param(\"contextId\", contextId)\n                        .send();\n                if (!response.isError() && Boolean.TRUE.equals(response.getResult(\"result.value\"))) {\n                    logger.trace(\"frame context ready: frameId={}, contextId={}\", frameId, contextId);\n                    return true;\n                }\n            } catch (Exception e) {\n                // Context not ready yet, will retry\n                logger.trace(\"frame context not ready yet: {}\", e.getMessage());\n            }\n            return false;\n        });\n        if (!ready) {\n            // Timeout is not fatal - retry logic in script() will handle it\n            logger.warn(\"timeout waiting for frame context: frameId={} (will retry on first use)\", frameId);\n        }\n    }\n\n    // ========== Lifecycle ==========\n\n    /**\n     * Close driver and browser.\n     */\n    public void quit() {\n        if (terminated) {\n            return;\n        }\n        terminated = true;\n        ACTIVE.remove(this);\n\n        logger.debug(\"quitting CDP driver\");\n\n        // Unblock anyone awaiting readiness (e.g. a script() racing this quit) - once","sourceCodeStart":2627,"sourceCodeEnd":2663,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java#L2627-L2663","documentation":"For same-origin frames, CdpDriver polls (1s bound) the frame's execution context with a trivial Runtime.evaluate (\"typeof document !== 'undefined'\") to confirm it can run JS. If the context is not confirmed ready within the bound, this warning is logged. It is deliberately non-fatal — script()'s retry logic handles the remainder on first use.","triggerScenarios":"switchFrame() followed immediately by evaluation while the frame's document is still loading, the contextId exists but the document isn't ready, or repeated eval errors during the 1s poll.","commonSituations":"Very large or slow-loading iframes, switching frames right after a navigation triggers new context creation, or CI machines slow enough that 1s of polling isn't enough.","solutions":["Let the built-in retry handle it (usually sufficient); if not, add an explicit waitFor on an element inside the frame after switchFrame.","Increase retryInterval in driver options to widen the effective first-use retry window.","Avoid switching frames during heavy navigation; wait for load events first.","Reload or re-attach if the context is persistently unready (stale context id)."],"exampleFix":"// before\ndriver.switchFrame(\"iframe#app\");\nString html = driver.script(\"document\", \"document.body.innerHTML\");\n// after\ndriver.switchFrame(\"iframe#app\");\ndriver.waitFor(\"body\");\nString html = driver.script(\"document\", \"document.body.innerHTML\");","handlingStrategy":"retry","validationCode":"driver.waitFor(\"iframe#app\");\ndriver.switchFrame(\"iframe#app\");\ndriver.waitFor(\"body\"); // ensure document exists before script()","typeGuard":null,"tryCatchPattern":"try {\n    Object v = driver.script(\"document\", expr);\n} catch (RuntimeException e) {\n    // context may still be warming: brief sleep + one retry\n    sleep(500);\n    Object v = driver.script(\"document\", expr);\n}","preventionTips":["Wait for an element in the frame before evaluating JS","Increase driver retryInterval for slow environments","Don't switch frames during active navigation"],"tags":["cdp","iframe","execution-context","timeout"],"backgroundTag":"frame-readiness-timeout","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}