{"record":{"id":"12a93d290a58a02c","repo":"karatelabs/karate","slug":"chrome-process-died-while-waiting-for-page-targets-exit-code","errorCode":null,"errorMessage":"chrome process died while waiting for page targets (exit code: {})","messagePattern":"chrome process died while waiting for page targets \\(exit code: (.+?)\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpLauncher.java","lineNumber":235,"sourceCode":"        HttpClient client = HttpClient.newBuilder()\n                .connectTimeout(Duration.ofSeconds(5))\n                .build();\n\n        long startTime = System.nanoTime();\n        long timeoutNanos = timeoutMs * 1_000_000L;\n        String url = \"http://\" + host + \":\" + port + \"/json\";\n        int intervalMs = 250;\n        int attemptCount = 0;\n\n        // Use elapsed time instead of attempt count to handle variable request durations\n        // Always make at least one attempt even if timeout is very small\n        while (attemptCount == 0 || (System.nanoTime() - startTime) < timeoutNanos) {\n            attemptCount++;\n\n            // Check if process died\n            if (process != null && !process.isAlive()) {\n                int exitCode = process.getExitCode();\n                logger.warn(\"chrome process died while waiting for page targets (exit code: {})\", exitCode);\n                return null;\n            }\n\n            try {\n                HttpRequest request = HttpRequest.newBuilder()\n                        .uri(URI.create(url))\n                        .timeout(Duration.ofSeconds(5))\n                        .GET()\n                        .build();\n\n                HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());\n                if (response.statusCode() == 200) {\n                    List<Map<String, Object>> targets = (List<Map<String, Object>>) JSONValue.parse(response.body());\n                    if (targets != null && !targets.isEmpty()) {\n                        // Look for a valid page target (same logic as v1)\n                        for (Map<String, Object> target : targets) {\n                            String targetUrl = (String) target.get(\"url\");\n                            String targetType = (String) target.get(\"type\");","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpLauncher.java#L217-L253","documentation":"WARN log from CdpLauncher.waitForWebSocketUrl when the launched Chrome process exits while Karate is polling the DevTargets HTTP endpoint to discover the WebSocket debugger URL. The method returns null, which causes start() to fail launching the driver.","triggerScenarios":"During startup, process.isAlive() becomes false while waiting for the page-targets list — Chrome crashed immediately after launch, failed to bind its debugging port, or was killed by the OS/CI.","commonSituations":"Missing --no-sandbox in root/Docker containers; Chrome version incompatibility with the CDP protocol; corrupted user-data-dir; port conflicts with an existing Chrome instance; OOM-kill in constrained CI memory.","solutions":["Match the exit code (logged) against Chrome startup failure docs; common codes indicate bad flags or missing deps.","In Docker/root, add --no-sandbox (or run as non-root) via driver addOptions.","Use a fresh, writable user-data-dir to avoid profile lock/corruption issues.","Check the debugging port isn't occupied and the Chrome version is compatible with the Karate/CDP driver.","Increase available memory in CI; Chrome often dies from OOM during startup."],"exampleFix":"// before\nkarate.configure('driver', { type: 'chrome' });\n// after (containerized / CI environment)\nkarate.configure('driver', {\n  type: 'chrome',\n  addOptions: ['--no-sandbox', '--disable-dev-shm-usage'],\n  userDataDir: '/tmp/karate-chrome-profile'\n});","handlingStrategy":"try-catch","validationCode":"// pre-launch sanity checks in CI\nassert new File(\"/dev/shm\").getFreeSpace() > 256 * 1024 * 1024; // ample shm\n// ensure debug port is free\ntry (var s = new java.net.ServerSocket(9222)) { /* free */ } catch (IOException e) { throw new IllegalStateException(\"port 9222 in use\"); }","typeGuard":null,"tryCatchPattern":"try {\n    driver = Driver.start(\"chrome\");\n} catch (RuntimeException e) {\n    // launcher returned null websocket url — chrome died at startup\n    logger.error(\"chrome failed to start: {}\", e.getMessage());\n    throw new SkipException(\"browser unavailable\", e);\n}","preventionTips":["Add --no-sandbox --disable-dev-shm-usage in Docker/root environments.","Pin a Chrome version known to work with your karate-core version.","Use a fresh user-data-dir per run to avoid profile corruption.","Ensure CI runners have enough memory for Chrome startup."],"tags":["chrome","process-crash","cdp","startup"],"backgroundTag":"browser-crashed","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}