Skip to content

Errors, cancellation, fallbacks ​

All failures reject with OptiqError (isOptiqError(e)), which has a code and sometimes details. Messages never contain image data or metadata.

CodeWhenWhat to do
INVALID_INPUTNot a Blob/File, or empty–
UNSUPPORTED_FORMATUnknown bytes, or HEIC/HEIFUpload the original, or convert server-side
MALFORMED_INPUTTruncated or corrupt fileUpload the original if your backend accepts it
INPUT_TOO_LARGEOver maxInputBytes / maxInputPixelsRaise the limits deliberately, or reject
INVALID_OPTIONSOption out of rangeFix the call
INCOMPATIBLE_OPTIONSOptions conflict with this imageRead the message; it names the option
CONSTRAINTS_UNSATISFIABLEonUnmetConstraints: "throw" and a constraint cannot be metRelax a constraint
CODEC_UNAVAILABLENo encoder could run for the required formatCheck CSP; allow fallback
UNSUPPORTED_ENVIRONMENTNo Web Workers (and allowMainThread not set)Upload the original
WORKER_ERRORWorker crashed or failed to loadCheck how the worker file is served
ABORTEDsignal aborted (name === "AbortError")–

Compression is always optional: in every case the original file is untouched and can be uploaded instead. compressAndUpload does this automatically.

Cancellation ​

Aborting a queued job removes it; aborting a running job terminates its worker, because a WASM encode cannot be interrupted. A new worker is started for the next job. Measured abort latency in Chromium: under 1 ms.

Fallbacks ​

SituationBehaviourReported in
A WASM codec cannot load (e.g. CSP without 'wasm-unsafe-eval')The browser's own encoder/decoder via OffscreenCanvasresult.fallbacks
A format has no working encoder at all (canvas cannot encode AVIF in Chromium)That format is skipped, others continueresult.warnings
codecFallback: "none"No canvas fallback–
No Web WorkersUNSUPPORTED_ENVIRONMENT, or main thread with allowMainThread: trueresult.fallbacks

Canvas fallback limits: premultiplied alpha (semi-transparent pixels may not round-trip, so lossless candidates can fail verification and the original is returned), no lossless WebP, no encoder tuning.