MRZ Scan Screen Wiki
Living documentation for the MRZ scan screen — deep linking, device-local storage, check-digit verification, the OCR pipeline, and the editor↔photo sync overlay.
Table of Contents
Guide
Table of Contents
Guide- Overview · Concept
- Deep Linking (?mrz=&scan=) · Feature
- Device-Local Storage · Feature
- Check-Digit Verification · Algorithm
- OCR Pipeline (Tesseract.js) · Technical
- Band Ladder & Repair · Technical
- Licence Barcode Mode (PDF417) · Feature
- URL Parameter Reference · Reference
- Exported Helper API · Reference
Overview
Concept
Overview
ConceptThe MRZ (Machine-Readable Zone) is the two- or three-line block at the bottom of passports, ID cards and visas, defined by ICAO Doc 9303. The scan screen at /mrz/scan reads that block on device with Tesseract.js, then hands the text to the same parseMrz the rest of the toolkit uses.
- On-device OCR — the MRZ photo is never uploaded; pixels stay in the browser tab.
- Deep linking — pass an MRZ in as
?mrz=<base64>to pre-fill the editor. - Device-local storage — the last verified read is remembered for 30 days.
- Check-digit verification — every read is graded verified or review.
- Licence mode — a separate card decodes a US/CA licence PDF417 barcode and maps it onto MRZ fields.
Supported formats: TD3 (passport, 2×44), TD1 (ID card, 3×30), TD2 (large ID card, 2×36), MRV-A (visa, 2×44) and MRV-B (visa, 2×36).
Deep Linking (?mrz=&scan=)
Feature
Deep Linking (?mrz=&scan=)
FeatureThe scan screen accepts two URL query parameters:
mrz — newline-separated MRZ lines, with | as the separator, URL-safe base64-encoded.scan — if false, pre-fill the OCR editor but stay on capture screen. If true or omitted, jump straight to the fix screen after parsing.Example:
/mrz/scan?mrz=PFJFQjAwMDA4MDAwOUAwMDAwMDAwMDA8PA==&scan=trueThe decoded payload is parsed with
parseMrz before being committed. If parsing fails, an error is shown and the user stays on the capture screen.Helpers in
OcrCard.tsx:decodeMrmzParam(value)— base64url-decode and split on|.encodeMrmzParam(lines)— join with|and base64url-encode.getScanPayload(url)— extract and validatemrzandscanparams.
Device-Local Storage
Feature
Device-Local Storage
FeatureThe scan screen remembers the last successful MRZ read using the browser's localStorage API. Nothing leaves the device.
Helpers in
lib/mrz/ocr.ts:restoreLastRead()— reads and validates the stored payload, returningnullif missing, stale, or corrupt.rememberLastRead(mrz, format)— persists a successful read with the current timestamp.
UI: A small "Recalled @{time}s ago" chip appears above the camera. Clicking it clears the recall.
Check-Digit Verification (ICAO 9303)
Algorithm
Check-Digit Verification (ICAO 9303)
AlgorithmEvery MRZ field has an adjacent check digit computed with the 7-3-1 algorithm. Each character is mapped to a numeric value, multiplied by weights 7, 3, 1, and the sum's last digit is the check digit.
Mismatches are highlighted inline next to the field that owns the check digit — no need to hunt through a status box. The validator is
validateMrzCheckDigits(mrz) in lib/mrz/validate.ts.Try live check-digit verification →
OCR Pipeline (Tesseract.js)
Technical
OCR Pipeline (Tesseract.js)
TechnicalOCR runs entirely in the browser using Tesseract.js with the eng traineddata model (5 MB, tracked in git at the project root).
- Camera captures a frame and isolates the MRZ region.
- Image is preprocessed (grayscale, threshold) for contrast.
- Tesseract.js worker runs inference with the
engmodel. - Raw text is split into lines and passed to
parseMrz. - Check digits are validated; mismatches are flagged.
- Result is committed to
localStorageand/or the editor.
Pre-existing test note: 2 failures in
ocrImages.test.ts are due to eng.traineddata not being downloadable in the Node test environment — unrelated to UI changes. On Vercel, the 5 MB model resolves correctly.Editor↔Photo Sync Overlay
Feature
Editor↔Photo Sync Overlay
FeatureWhen the OCR editor has a parsed document (from OCR or from a deep link), the screen shows a synchronized view: the photo (or its OCR patch) alongside the editor, with fields that differ between the two highlighted.
- Fields extracted from OCR that don't match editor input are yellow-highlighted.
- Check-digit mismatches are red-highlighted inline.
- Clicking a highlighted field jumps the editor cursor to that position.
- The overlay can be toggled via a button in the top-right of the photo panel.
URL Parameter Reference
Reference
URL Parameter Reference
Reference| Parameter | Type | Default | Description |
|---|---|---|---|
mrz | base64url | — | Base64url-encoded MRZ lines, |-separated. |
scan | boolean | true | If false, stay on capture screen after pre-filling editor. |