Browser example
An interactive Vite web page that decodes images directly in your browser. Opens in StackBlitz with no account needed.
Open in StackBlitzWASM + Python
StackBlitz, Binder, Colab
Code 128 + QR code
MIT
Try hosted browser demos, runnable Vite and Jupyter projects or the examples bundled with the browser SDK and CLI.
Links verified on 27 November 2026. The StackBlitz, Binder and Google Colab links open a pinned release tag of the scanner repository so they continue running the exact same files; the GitHub Pages live demo and Hugging Face Space reflect the published release.
Both the browser example and the notebook start from a fresh clone of the scanner repository. If you have already cloned it, omit the git clone command and run the notebook commands from the repository root. Each example installs the published package at an exact pinned version.
You need Node.js 20.19 or later, or 22.12 or later. The directory is self-contained: npm ci installs dependencies from its lockfile and npm run dev starts the page. Open the local address that Vite prints.
git clone https://github.com/qrcode-ai-com/qrcode-barcode-scanner-rust.git
cd qrcode-barcode-scanner-rust/examples/web-vite
npm ci
npm run dev
npm run build writes the static site to dist/, and npm run preview serves that directory locally.
You need Python 3 with its venv module. The first installation verifies the hash of every package file, so JupyterLab is installed in a second step. Once open, choose Run All in the notebook.
git clone https://github.com/qrcode-ai-com/qrcode-barcode-scanner-rust.git
cd qrcode-barcode-scanner-rust
python3 -m venv .venv
.venv/bin/python -m pip install -r binder/requirements.txt
.venv/bin/python -m pip install jupyterlab
.venv/bin/jupyter lab examples/notebooks/scan-images.ipynb
On Windows, these commands live under .venv\Scripts\.
These snippets come straight from the two examples. In the browser, a module Web Worker initialises the scanner once and calls scan_image on the selected image’s bytes. In Python, scan accepts the image bytes and a profile, which controls how much analysis the scan performs. Both pass a time budget of 0 so every scan runs to completion.
// A module worker that owns one scanner. The page posts { id, type: 'load' } once, then
// { id, type: 'scan', bytes, profile } for each image, and gets one reply with the same id:
// { id, ok: true, version, variant } after 'load'
// { id, ok: true, report, ms } after 'scan'
// { id, ok: false, phase, error } phase: 'load' or 'scan'
// Scanning in a worker keeps the page responsive while an image is decoded.
import { createScannerLoader } from '@qrcode-ai-com/qrcode-barcode-scanner-wasm/auto';
// One loader for the life of this worker. It fetches and compiles the WebAssembly module once.
const load = createScannerLoader();
// 0 removes the time budget: every scan runs to its end.
const BUDGET_MS = 0;
function describe(error) {
const message = error && error.message !== undefined ? String(error.message) : String(error);
const qrs = /\[(QRS-\d{3})\]/.exec(message);
return {
name: error && error.name ? String(error.name) : 'Error',
message,
// A loading failure carries a stable code; a refused input ends with [QRS-xxx].
code: error && typeof error.code === 'string' ? error.code : null,
qrs: qrs ? qrs[1] : null,
};
}
self.onmessage = async ({ data }) => {
const { id, type } = data;
let phase = 'load';
try {
const scanner = await load();
if (type === 'load') {
self.postMessage({ id, ok: true, version: scanner.version(), variant: scanner.variant });
return;
}
phase = 'scan';
const started = performance.now();
const report = scanner.scan_image(new Uint8Array(data.bytes), data.profile, undefined,
undefined, BUDGET_MS);
self.postMessage({ id, ok: true, report, ms: performance.now() - started });
} catch (error) {
self.postMessage({ id, ok: false, phase, error: describe(error) });
}
};
The Python snippet is a single cell from the notebook. Earlier cells import qrcode_barcode_scanner as scanner and read the sample image bytes into sample.
Choose Run All. Among the output lines, the notebook prints the seven lines below. The first three show the codes detected under the fast, frame and full profiles: every profile returns the same two codes (the cell sorts them by symbology, so code128 appears before qr_code). The fourth shows the scannability score, from 0 to 100, that the full profile computes for the first code in the report: in this case the QR code, since a report lists QR codes first.
The full notebook outputs more than this excerpt. Before running the scans, an earlier cell prints the Python version and platform, the package version, the SHA-256 digest of the installed module and the name of its PyPI wheel. After the score, another cell prints four lines for each detected code: for the barcode, its symbology (code128), its decoded text (STOCK-4827), its payload type (text, meaning plain text) and “measured as segment” with two points along the scan line.
fast code128: STOCK-4827 · qr_code: https://qrc-ai.com/76xMa
frame code128: STOCK-4827 · qr_code: https://qrc-ai.com/76xMa
full code128: STOCK-4827 · qr_code: https://qrc-ai.com/76xMa
Scannability of the first code: 100 out of 100, excellent
White image: no code found, and the scan finished.
Not an image: unsupported or corrupt image: The image format could not be determined [QRS-001]
Set MY_IMAGE to the path of an image, then run this cell again.
The final three lines cover the blank image with no code, the non-image file and the last cell, which waits for the path to your own image.
A Web Worker owns the scanner. The page passes the selected image’s bytes to a module Web Worker. The Worker initialises the scanner once using createScannerLoader from the package’s /auto entry point, then calls scan_image.
The page stays responsive. Because decoding executes inside the Worker, the interface remains responsive during scanning and the image never leaves your device.
Two Vite settings. optimizeDeps.exclude excludes the package so its modules can locate the adjacent .wasm file. worker.format is set to es, as required by the /auto loader.
Mixed sample output. The sample image includes one Code 128 barcode (STOCK-4827) and one QR code (https://qrc-ai.com/76xMa). Each detection reports symbology and content.text; preserve leading zeros and look up product details in a separate catalogue or database.
Format mapping and scoring. Symbology names the underlying printed format (GS1-128 → code128, ITF-14 → itf, ISBN → ean13). The frame profile skips scoring, whilst fast and full score the first code without certifying label print quality.
Empty scans and input errors. An image containing no code returns an empty list. Non-image files fail with QRS-001 (Error in JavaScript, ValueError in Python).
Run the sample image first, test your own image and then bring the scan call into your codebase.
Launch an example online or on your local machine and decode the sample image. You should get the value STOCK-4827, read as Code 128.
Select a file in the browser page, or enter its path in the final cell of the notebook. Inspect the decoded text and the payload type.
Copy the Worker or scan snippet, keep the package version pinned in your lockfile and follow the SDK guide for your language.
These references track the main branch of the scanner repository.
Running online, the sample image, your own images, empty results and code reuse.
The Barcode Scanner examples include standalone projects that run the published packages of the QR Code & Barcode Scanner, QR Code AI’s open-source MIT library: a browser page built with Vite (hosted on StackBlitz, GitHub Pages and Hugging Face Spaces) and a Python Jupyter notebook (hosted on Binder and Google Colab). Each project installs a pinned published package and decodes a sample image so you can inspect real output before writing any code. Both also run on your local machine from the examples directory on GitHub.
No account is needed for StackBlitz, GitHub Pages, Hugging Face Spaces or Binder. StackBlitz installs and runs the Vite project directly in your browser, GitHub Pages serves the compiled static page straight away and Binder builds a temporary Python session (start-up takes a few minutes and the session ends after about ten minutes of inactivity). Google Colab runs the same Python notebook, though it requires a signed-in Google account.
Try the browser example first if you are building a web page or web app: it demonstrates the scanner running inside a Web Worker, with images staying on your device. Start with the Python notebook if you work in Python or want to inspect images step by step. For terminal scripts or a CI pipeline, use the Barcode Scanner CLI instead.
The sample image contains one Code 128 barcode and one QR code, so scanning it returns both: the Code 128 barcode with the value STOCK-4827 and the QR code with the link https://qrc-ai.com/76xMa. The fast, frame and full profiles all decode the same two codes. Each result reports its symbology, allowing your code to keep the barcodes and ignore the rest.
You can test any format that the scanner supports. That covers the retail formats EAN-13, EAN-8, UPC-A and UPC-E, the linear formats Code 128, Code 39, Code 93, Codabar, ITF and Telepen, GS1 DataBar and GS1 DataBar Expanded, as well as the 2D formats Data Matrix, PDF417, Aztec and MaxiCode. The included sample image tests Code 128; to test another symbology, select your own image in the browser page or point the notebook to its file path.
No. In the browser example, the scanner runs as WebAssembly inside a Web Worker in your own browser, so your image stays on your device and is never uploaded to a server. In the Python notebook, decoding happens inside its Python session and the image is sent nowhere else: on your local machine that session is entirely local, whereas on Binder or Google Colab the session runs on the host’s servers, so any image you add there is uploaded to that host and you should only add images you are able to share.
The scanner returns any codes it detects, or an empty list when none are present. An empty list is a valid outcome rather than an error, and the browser example simply reports that no code was found. An image containing only a QR code returns that QR code, so check each result’s symbology before treating it as a barcode. A file that is not an image is handled differently: the scanner refuses it with the input error QRS-001, and the Python package raises ValueError. Both examples demonstrate the blank image and the refused file.
Yes. The examples and current scanner packages are distributed under the MIT licence, so you may use, modify and ship them in open-source or commercial proprietary projects provided you retain the copyright and licence notices. Check the licensing guide for retained third-party notices.
No. Decoding an existing image is completely separate from QR Code AI’s creation service and its generation API. That creation service has free creation limits and a seven-day Premium trial triggered by creating the first dynamic QR code or Smart Link, with Premium required to continue the affected features afterwards. Running the examples or reading a code uses no generation credits, does not start that trial and leaves directly encoded data unchanged in the symbol. The scanner itself is open source under the MIT licence.