{"record":{"id":"09c5fa481cb3cad7","repo":"karatelabs/karate","slug":"screenshotonfailure-capture-failed-continuing","errorCode":null,"errorMessage":"screenshotOnFailure: capture failed, continuing: {}","messagePattern":"screenshotOnFailure: capture failed, continuing: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java","lineNumber":2005,"sourceCode":"     * map first, falling back to the driver instance's frozen options. This\n     * lets per-scenario overrides take effect under pooled-driver reuse, where\n     * the driver instance's options reflect creation-time config not the\n     * current scenario's.\n     */\n    private void captureScreenshotOnFailure(StepResult sr) {\n        if (driver == null || driver.isTerminated()) {\n            return;\n        }\n        try {\n            if (!isScreenshotOnFailureEnabled()) {\n                return;\n            }\n            byte[] bytes = driver.failureScreenshot();\n            if (bytes != null && bytes.length > 0) {\n                sr.addEmbed(new StepResult.Embed(bytes, \"image/png\", \"screenshot.png\"));\n            }\n        } catch (Throwable t) {\n            logger.warn(\"screenshotOnFailure: capture failed, continuing: {}\", t.toString());\n        }\n    }\n\n    @SuppressWarnings(\"rawtypes\")\n    private boolean isScreenshotOnFailureEnabled() {\n        Object cfg = config.getDriverConfig();\n        if (cfg instanceof Map map && map.containsKey(\"screenshotOnFailure\")) {\n            Object v = map.get(\"screenshotOnFailure\");\n            return v == null || Boolean.parseBoolean(String.valueOf(v));\n        }\n        try {\n            return driver.getOptions().isScreenshotOnFailure();\n        } catch (Exception e) {\n            return true;\n        }\n    }\n\n    /**","sourceCodeStart":1987,"sourceCodeEnd":2023,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/ScenarioRuntime.java#L1987-L2023","documentation":"When `screenshotOnFailure` is enabled, Karate attempts a failure screenshot via the driver after a step fails. If any Throwable occurs during capture, it is logged as this warning and the scenario continues; the failure result itself is unaffected.","triggerScenarios":"A step failed and Karate calls `driver.failureScreenshot()`, which throws (driver crashed, session already dead, WebSocket/CDP connection broken).","commonSituations":"Browser terminated before the failure screenshot; driver process OOM-killed; remote grid session expired mid-scenario; Driver wrapper in a bad state after a hard failure.","solutions":["Treat as secondary symptom: first diagnose why the step failed and why the driver is unhealthy","Check driver/browser logs for a crash or session termination","Disable screenshotOnFailure if capture noise obscures the real failure","Reconnect/restart the driver infrastructure (grid node, container)"],"exampleFix":"// before\nconfigure screenshotOnFailure = true\n// after (suppress noisy captures in unstable environments)\nconfigure screenshotOnFailure = karate.env != 'ci-smoke'","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Karate already catches internally; on your side guard any post-failure driver use:\ntry { var bytes = driver.failureScreenshot(); } catch (t) { karate.log('screenshot skipped', t); }","preventionTips":["Keep the browser session healthy (reasonable timeouts, avoid killing processes)","Skip screenshotOnFailure in environments with flaky drivers","Diagnose the primary step failure first; this warning is secondary"],"tags":["karate","screenshot","driver"],"backgroundTag":"browser-session-closed","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"}