{"record":{"id":"95e5820e78660d56","repo":"karatelabs/karate","slug":"cdp-timeout-for-method","errorCode":null,"errorMessage":"CDP timeout for: {method}","messagePattern":"CDP timeout for: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpClient.java","lineNumber":270,"sourceCode":"     * Set the session ID for subsequent requests.\n     * Used when switching between page targets.\n     */\n    public void setSessionId(String sessionId) {\n        this.sessionId = sessionId;\n    }\n\n    // Send methods\n\n    /**\n     * Blocking send with response.\n     */\n    CdpResponse send(CdpMessage message) {\n        try {\n            return sendAsync(message).join();\n        } catch (CompletionException e) {\n            Throwable cause = e.getCause();\n            if (cause instanceof TimeoutException) {\n                throw new RuntimeException(\"CDP timeout for: \" + message.getMethod());\n            }\n            if (cause instanceof RuntimeException) {\n                throw (RuntimeException) cause;\n            }\n            throw new RuntimeException(\"CDP error: \" + cause.getMessage(), cause);\n        }\n    }\n\n    /**\n     * Async send with response tracking.\n     */\n    CompletableFuture<CdpResponse> sendAsync(CdpMessage message) {\n        // Fail fast if connection is closed\n        if (!ws.isOpen()) {\n            return CompletableFuture.failedFuture(\n                    new WsException(WsException.Type.CONNECTION_CLOSED, \"websocket not open\"));\n        }\n","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpClient.java#L252-L288","documentation":"CdpClient.send() waits synchronously for a CDP response via CompletableFuture.join(). If the future completes with a TimeoutException, this RuntimeException is thrown naming the CDP method that timed out. The browser never replied to the command within the client's timeout window.","triggerScenarios":"Sending a CDP command to a hung or closed browser; a command whose response is delayed beyond the CDP timeout (slow page, blocked renderer); websocket silently dropped so the response never arrives; commands sent while the target is paused in the debugger.","commonSituations":"Page stuck on a long navigation/script while Karate sends CDP commands; browser process frozen or OOM-killed; debugger breakpoint (paused) blocking command processing; slow CI machines exceeding the timeout; network.throttle or heavy resources delaying responses.","solutions":["Retry the operation or the scenario — transient hangs often clear","Check the browser process is alive and not frozen/paused (remove debugger pauses, attach no paused debugger)","Increase the CDP timeout configuration if legitimate operations are slow","Investigate page health: heavy scripts, endless navigation, or blocked renderer causing missed responses","Reconnect/relaunch the driver if the websocket is dead"],"exampleFix":"// before: dialog blocks CDP processing, causing timeouts\nDriver driver = karate.driver;\ndriver.dialog(); // auto-dismiss misconfigured -> page paused\n// after: handle dialogs so CDP commands flow\nkarate.configure(\"driver\", { type: 'chrome', addOptions: ['--headless=new'] });\n// and use Dialog API to accept dialogs promptly","handlingStrategy":"retry","validationCode":"// ensure the browser session is alive before sending CDP commands\nif (driver.isTerminated()) { driver = restartDriver(); }","typeGuard":"null","tryCatchPattern":"try { CdpResponse r = client.method(\"Page.navigate\").param(\"url\", u).send(); }\ncatch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"CDP timeout for:\")) {\n        retryOnce(this::send); // or increase timeout\n    } else throw e;\n}","preventionTips":["Avoid debugger pauses that block CDP processing","Increase CDP timeout on slow pages/CI machines","Handle dialogs promptly so commands are not queued indefinitely","Monitor browser process health (OOM kills)"],"tags":["cdp","timeout","websocket"],"backgroundTag":"request-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"}