gchq/CyberChef · error · OperationError
This operation only works in a browser
Error message
This operation only works in a browser
What it means
Thrown by OpticalCharacterRecognition.run when isWorkerEnvironment() is false. OCR uses tesseract.js which spins up a Web Worker and references browser-only globals (self.docURL, self.sendStatusMessage), so it cannot run in the Node.js API / Node package build of CyberChef.
Source
Thrown at src/core/operations/OpticalCharacterRecognition.mjs:59
},
{
name: "OCR Engine Mode",
type: "option",
value: OEM_MODES,
defaultIndex: 1
}
];
}
/**
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
async run(input, args) {
const [showConfidence, oemChoice] = args;
if (!isWorkerEnvironment()) throw new OperationError("This operation only works in a browser");
const type = isImage(input);
if (!type) {
throw new OperationError("Unsupported file type (supported: jpg,png,pbm,bmp) or no file provided");
}
const assetDir = `${self.docURL}/assets/`;
const oem = OEM_MODES.indexOf(oemChoice);
try {
self.sendStatusMessage("Spinning up Tesseract worker...");
const image = `data:${type};base64,${toBase64(input)}`;
const worker = await createWorker("eng", oem, {
workerPath: `${assetDir}tesseract/worker.min.js`,
langPath: `${assetDir}tesseract/lang-data`,
corePath: `${assetDir}tesseract/tesseract-core.wasm.js`,
logger: progress => {
if (isWorkerEnvironment()) {View on GitHub (pinned to 4290ea7539)
Solutions
- Run this operation in the browser UI or a worker context only.
- For server-side OCR use tesseract.js directly (or another OCR library) outside CyberChef.
- Remove the OCR step from Node-side recipes and perform OCR in a browser step.
Defensive patterns
Strategy: type-guard
Validate before calling
import { isWorkerEnvironment } from "core/Utils.mjs";
if (!isWorkerEnvironment()) {
// do not include OCR in Node-side recipes; run it in the browser
} Type guard
const canRunOCR = () => typeof self !== "undefined" && isWorkerEnvironment();
Prevention
- Restrict OCR steps to browser/worker recipes.
- For Node OCR, call tesseract.js directly instead of via CyberChef.
- Gate the recipe branch on isWorkerEnvironment() before invoking.
When it happens
Trigger: run(input, args) invoked outside a Web Worker — e.g. via the Node REPL (npm run repl), the CyberChef Node library, or a server-side recipe. The check fires before any image validation.
Common situations: Using CyberChef as an npm dependency in a Node service; running recipes via the Node build that include OCR; scripting batch processing server-side; CI pipeline executing recipes headlessly.
Related errors
- Unsupported file type (supported: jpg,png,pbm,bmp) or no fil
- Error performing OCR on image. (${err})
- Sorry, the ${name} operation is not available in the Node.js
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/502aa27ca0ddc4b1.
Report an issue: GitHub.