{"record":{"id":"15e8a2afed1b416c","repo":"karatelabs/karate","slug":"readystate-check-failed","errorCode":null,"errorMessage":"readyState check failed: {}","messagePattern":"readyState check failed: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"info","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java","lineNumber":819,"sourceCode":"     * Check if the current page is already loaded (document.readyState is 'complete' or 'interactive').\n     * This handles the case where we connect to an already-loaded page or the event was missed.\n     */\n    private void checkIfPageAlreadyLoaded() {\n        try {\n            CdpResponse response = cdp.method(\"Runtime.evaluate\")\n                    .param(\"expression\", \"document.readyState\")\n                    .param(\"returnByValue\", true)\n                    .send();\n            String readyState = response.getResultAsString(\"result.value\");\n            if (\"complete\".equals(readyState) || \"interactive\".equals(readyState)) {\n                if (!domContentEventFired) {\n                    logger.debug(\"page already loaded (readyState={}), setting domContentEventFired\", readyState);\n                    domContentEventFired = true;\n                }\n            }\n        } catch (Exception e) {\n            // Ignore - this is just a safety check\n            logger.warn(\"readyState check failed: {}\", e.getMessage());\n        }\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private void setupEventHandlers() {\n        // Listen to BOTH lifecycle events AND domContentEventFired for maximum compatibility\n        // Page.lifecycleEvent is more reliable per-frame (Puppeteer approach)\n        // Page.domContentEventFired is a fallback for environments where lifecycle events don't fire\n        //\n        // NOTE on session filtering: with OOPIF support, Page.enable is called on every isolated\n        // iframe session, so those sessions also stream Page.* events into this client. Without\n        // a sessionId filter, an OOPIF's DOMContentLoaded would flip the parent's domContentEventFired\n        // prematurely, and an OOPIF's frameStartedLoading would leak its frameId into\n        // framesStillLoading. Every Page.* handler that mutates parent state must reject events\n        // whose sessionId is not the current page session.\n        cdp.on(\"Page.lifecycleEvent\", event -> {\n            if (isFromOtherSession(event)) return;\n            String name = event.get(\"name\");","sourceCodeStart":801,"sourceCodeEnd":837,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java#L801-L837","documentation":"CdpDriver performs a best-effort readyState check (evaluating document.readyState to decide whether domContentEventFired already happened) and swallows any exception, logging this warning. The check is a safety net; failure means the load-detection fast path could not run and normal lifecycle events will be relied upon.","triggerScenarios":"The evaluate call for document.readyState throwing — websocket hiccup, navigation racing the check, or page context destroyed mid-check.","commonSituations":"Rapid navigations in a scenario (check runs while the execution context is being swapped); about:blank or detached frames lacking a document; CDP channel briefly busy after Page.navigate.","solutions":["Usually ignorable — Karate falls back to lifecycle events for load detection","If it precedes hangs, add explicit waitFor/Page.navigate guards and avoid navigating while a previous navigation is in flight","Check that the websocket connection is stable (no proxy timeouts) if this appears frequently"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// driver-internal check; callers rely on load events\n// wrap navigation with explicit wait:\ndriver.setUrl(url);\ndriver.waitUntil(\"document.readyState == 'complete'\");","preventionTips":["Avoid rapid back-to-back navigations","Use explicit waitFor on readyState instead of relying on implicit detection","Keep the CDP websocket stable (no idle-proxies dropping it)"],"tags":["cdp","readystate","page-load","best-effort"],"backgroundTag":"unexpected-response-shape","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"}