gchq/CyberChef · error · OperationError
Error performing OCR on image. (${err})
Error message
Error performing OCR on image. (${err}) What it means
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.
Source
Thrown at src/core/operations/OpticalCharacterRecognition.mjs:91
workerPath: `${assetDir}tesseract/worker.min.js`,
langPath: `${assetDir}tesseract/lang-data`,
corePath: `${assetDir}tesseract/tesseract-core.wasm.js`,
logger: progress => {
if (isWorkerEnvironment()) {
self.sendStatusMessage(`Status: ${progress.status}${progress.status === "recognizing text" ? ` - ${(parseFloat(progress.progress)*100).toFixed(2)}%`: "" }`);
}
}
});
self.sendStatusMessage("Finding text...");
const result = await worker.recognize(image);
if (showConfidence) {
return `Confidence: ${result.data.confidence}%\n\n${result.data.text}`;
} else {
return result.data.text;
}
} catch (err) {
throw new OperationError(`Error performing OCR on image. (${err})`);
}
}
}
export default OpticalCharacterRecognition;
View on GitHub (pinned to 4290ea7539)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
import { isImage } from '../lib/FileType.mjs';
if (!isImage(input)) {
throw new Error('Input is not a supported image (jpg/png/pbm/bmp)');
} Try / catch
try {
const text = await op.run(inputBuf, [true, 'LSTM only']);
} catch (e) {
if (e instanceof OperationError && /Error performing OCR/.test(e.message)) {
// inner cause is appended after 'image. ('
console.error('OCR failed:', e.message);
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unsupported file type (supported: jpg,png,pbm,bmp) or no fil
- Error opening image. (${err})
- Error normalising image. (${err})
- Could not read a QR code from the image.
- Invalid file type.
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/7f579e15dd6209e9.
Report an issue: GitHub.