{"record":{"id":"dade44c7e9576a67","repo":"karatelabs/karate","slug":"no-diff-image-available-ran-in-compareonly-mode","errorCode":null,"errorMessage":"No diff image available - ran in compareOnly mode","messagePattern":"No diff image available - ran in compareOnly mode","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"karate-image/src/main/resources/META-INF/karate-ext/static/resemble.js","lineNumber":673,"sourceCode":"                }\n\n                if (compareOnly) {\n                    var currentMisMatchPercent = (mismatchCount / (height * width)) * 100;\n\n                    if (currentMisMatchPercent > returnEarlyThreshold) {\n                        skipTheRest = true;\n                    }\n                }\n            });\n\n            data.rawMisMatchPercentage = (mismatchCount / (height * width)) * 100;\n            data.misMatchPercentage = data.rawMisMatchPercentage.toFixed(2);\n            data.diffBounds = diffBounds;\n            data.analysisTime = Date.now() - time;\n\n            data.getImageDataUrl = function (text) {\n                if (compareOnly) {\n                    throw Error(\"No diff image available - ran in compareOnly mode\");\n                }\n\n                var barHeight = 0;\n\n                if (text) {\n                    barHeight = addLabel(text, context, hiddenCanvas);\n                }\n\n                context.putImageData(imgd, 0, barHeight);\n\n                return hiddenCanvas.toDataURL(\"image/png\");\n            };\n\n            if (!compareOnly && hiddenCanvas.toBuffer) {\n                data.getBuffer = function (includeOriginal) {\n                    if (includeOriginal) {\n                        var imageWidth = hiddenCanvas.width + 2;\n                        hiddenCanvas.width = imageWidth * 3;","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-image/src/main/resources/META-INF/karate-ext/static/resemble.js#L655-L691","documentation":"resemble.js's getImageDataUrl() builds a visual diff image, but when the comparison ran in compareOnly mode no diff canvas exists, so calling it throws this JavaScript Error. In Karate image testing this means you requested the diff image output from a comparison that was configured to only compute the mismatch percentage.","triggerScenarios":"Calling data.getImageDataUrl(text) (or requesting diff-image output from karate's image match config) on a resemblance result produced with compareOnly enabled.","commonSituations":"karate-config for image matching set to compareOnly to save time/space, then later code (report generation, failure output) tries to render a diff image.","solutions":["Disable compareOnly in the image-comparison configuration so a diff image is generated","Wrap getImageDataUrl in a check/try so it's only called when compareOnly is false","If you only need the mismatch percentage, avoid calling getImageDataUrl entirely"],"exampleFix":"// before\nvar diff = result.getImageDataUrl('diff'); // throws in compareOnly\n// after\nif (!result.compareOnly) { var diff = result.getImageDataUrl('diff'); } else { karate.warn('diff image skipped'); }\n// or re-run comparison with compareOnly = false in config","handlingStrategy":"fallback","validationCode":"// before requesting a diff image\nif (config.compareOnly) { karate.warn('compareOnly mode: no diff image'); } else { /* getImageDataUrl safe */ }\n","typeGuard":"function hasDiffImage(result) { return !result.compareOnly; }\n","tryCatchPattern":"try { diffUrl = result.getImageDataUrl('diff'); } catch (e) { diffUrl = null; /* compareOnly mode */ }\n","preventionTips":["Enable diff-image mode in config when reports need diffs","Guard getImageDataUrl calls behind a compareOnly check","Keep compareOnly only for fast percentage-only checks"],"tags":["javascript","image-comparison","resemble","config"],"backgroundTag":"feature-not-enabled","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"}