{"record":{"id":"c0d5873a81fb1a51","repo":"karatelabs/karate","slug":"cdp-connection-failed-readiness-check-message","errorCode":null,"errorMessage":"CDP connection failed readiness check: {message}","messagePattern":"CDP connection failed readiness check: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpClient.java","lineNumber":131,"sourceCode":"    /**\n     * Wait for CDP to be ready by sending a simple command.\n     * This verifies the WebSocket connection is fully established and CDP is responsive.\n     */\n    private void waitForReady() {\n        try {\n            // Use a shorter timeout for readiness check\n            Duration readyTimeout = defaultTimeout.compareTo(Duration.ofSeconds(10)) > 0\n                    ? Duration.ofSeconds(10) : defaultTimeout;\n            CdpMessage message = new CdpMessage(this, nextId(), \"Browser.getVersion\");\n            message.timeout(readyTimeout);\n            CdpResponse response = send(message);\n            if (response.isError()) {\n                logger.warn(\"CDP readiness check returned error: {}\", response.getErrorMessage());\n            } else {\n                logger.debug(\"CDP ready, browser: {}\", response.getResult().get(\"product\"));\n            }\n        } catch (Exception e) {\n            throw new RuntimeException(\"CDP connection failed readiness check: \" + e.getMessage(), e);\n        }\n    }\n\n    private void setupMessageHandler() {\n        ws.onMessage(frame -> {\n            if (frame.isText()) {\n                handleMessage(frame.getText());\n            }\n        });\n        ws.onClose(() -> {\n            // Complete all pending futures exceptionally\n            for (PendingRequest pr : pending.values()) {\n                pr.future.completeExceptionally(\n                        new WsException(WsException.Type.CONNECTION_CLOSED, \"websocket closed\"));\n            }\n            pending.clear();\n        });\n        ws.onError(error -> {","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpClient.java#L113-L149","documentation":"After opening the DevTools websocket, waitForReady sends a probe CDP command (Browser.getVersion). Any exception during that handshake is wrapped as 'CDP connection failed readiness check: <cause message>'. The connection was established but the browser did not answer the readiness probe correctly.","triggerScenarios":"Browser closes or crashes immediately after launch (port raced, wrong executable); wrong websocket endpoint URL; the browser responds with a CDP error to the readiness command; a non-Chrome/unsupported browser on the DevTools port; proxy or firewall interfering with the local DevTools socket.","commonSituations":"chrome/edge binary path misconfigured so something else listens on the port; browser version mismatch with the driver's CDP expectations; browser exits early in CI containers (missing deps, no sandbox flags); stale browser process occupying the debug port.","solutions":["Read the wrapped cause message (e.getMessage()) — it names the real failure (connection reset, CDP error, etc.) and fix that","Verify the browser executable path launches a supported Chrome/Chromium/Edge version","Kill stale processes holding the DevTools port and retry","In containers, add required flags (e.g. --no-sandbox) and ensure shared memory/deps are present","Disable proxies for localhost so the DevTools websocket is not intercepted"],"exampleFix":"// before: wrong binary\nkarate.configure(\"driver\", { type: 'chrome', executable: '/usr/bin/chromium-browser' }); // stale wrapper that exits\n// after: valid supported binary\nkarate.configure(\"driver\", { type: 'chrome', executable: '/usr/bin/google-chrome' });","handlingStrategy":"retry","validationCode":"// pre-check the DevTools endpoint before connecting\nSocket s = new Socket();\nboolean ok = s.isConnected(); // after s.connect(new InetSocketAddress(\"localhost\", port), 2000)\ns.close();","typeGuard":"null","tryCatchPattern":"try { connect(); }\ncatch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"CDP connection failed readiness check\")) {\n        retryWithBackoff(3, this::connect); // relaunch browser each attempt\n    } else throw e;\n}","preventionTips":["Verify the browser binary path launches a supported Chrome/Edge","Kill stale processes on the DevTools port before launching","Disable proxies for localhost","Add container flags (--no-sandbox) and check browser version compatibility"],"tags":["cdp","websocket","browser-launch"],"backgroundTag":"connection-refused","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"}