{"record":{"id":"7f579e15dd6209e9","repo":"gchq/CyberChef","slug":"error-performing-ocr-on-image-err","errorCode":null,"errorMessage":"Error performing OCR on image. (${err})","messagePattern":"Error performing OCR on image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/OpticalCharacterRecognition.mjs","lineNumber":91,"sourceCode":"                workerPath: `${assetDir}tesseract/worker.min.js`,\n                langPath: `${assetDir}tesseract/lang-data`,\n                corePath: `${assetDir}tesseract/tesseract-core.wasm.js`,\n                logger: progress => {\n                    if (isWorkerEnvironment()) {\n                        self.sendStatusMessage(`Status: ${progress.status}${progress.status === \"recognizing text\" ? ` - ${(parseFloat(progress.progress)*100).toFixed(2)}%`: \"\" }`);\n                    }\n                }\n            });\n            self.sendStatusMessage(\"Finding text...\");\n            const result = await worker.recognize(image);\n\n            if (showConfidence) {\n                return `Confidence: ${result.data.confidence}%\\n\\n${result.data.text}`;\n            } else {\n                return result.data.text;\n            }\n        } catch (err) {\n            throw new OperationError(`Error performing OCR on image. (${err})`);\n        }\n    }\n}\n\nexport default OpticalCharacterRecognition;\n","sourceCodeStart":73,"sourceCodeEnd":97,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/OpticalCharacterRecognition.mjs#L73-L97","documentation":"Catch-all wrapper around the entire Tesseract.js OCR workflow in OpticalCharacterRecognition.run: Web Worker creation (createWorker with the 'eng' language model and WASM core), worker.recognize on a base64 data-URI, and result extraction. Any exception anywhere in that try block is re-thrown as a single OperationError, with the real cause interpolated via ${err}. isWorkerEnvironment and isImage are checked before this block, so this error is specifically about worker/recognize runtime failure.","triggerScenarios":"tesseract.js fails to fetch worker.min.js, lang-data/eng.traineddata, or tesseract-core.wasm.js from the assetDir (${self.docURL}/assets/tesseract/); the input ArrayBuffer passes isImage (magic bytes ok) but the pixel data is corrupt so worker.recognize rejects; WebAssembly is unavailable or blocked by CSP/policy; the worker times out on a very large image.","commonSituations":"Running CyberChef offline/airgapped where the asset directory is unreachable; self.docURL misconfigured so asset URLs 404; a browser with WASM disabled; feeding a valid-looking but truncated image; tesseract.js version drift where the bundled worker/core/lang assets no longer match the installed package.","solutions":["Read the interpolated ${err}: a 'Failed to fetch' / 404 points at missing tesseract assets - verify ${self.docURL}/assets/tesseract/{worker.min.js,lang-data,tesseract-core.wasm.js} are served and reachable.","If err mentions WASM, confirm WebAssembly is enabled in the browser and the .wasm.js core loads.","Re-export or re-drop the image and confirm it opens in an image viewer (isImage only checks magic bytes, not full integrity).","Try a different OCR Engine Mode argument (Tesseract only / LSTM only / Combined) to isolate engine-specific failures."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import { isImage } from '../lib/FileType.mjs';\nif (!isImage(input)) {\n    throw new Error('Input is not a supported image (jpg/png/pbm/bmp)');\n}","typeGuard":null,"tryCatchPattern":"try {\n    const text = await op.run(inputBuf, [true, 'LSTM only']);\n} catch (e) {\n    if (e instanceof OperationError && /Error performing OCR/.test(e.message)) {\n        // inner cause is appended after 'image. ('\n        console.error('OCR failed:', e.message);\n    } else throw e;\n}","preventionTips":["Ensure the tesseract asset directory is bundled and served (verify self.docURL resolves to /assets/tesseract).","Validate input is a real image with isImage before running.","Keep WASM enabled and the tesseract.js version in sync with the bundled worker/lang/core assets.","Test OCR against a known-good PNG first to separate asset-load failures from image-specific failures."],"tags":["ocr","tesseract","wasm","browser","image"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}