JavaScript QR Code Scanner SDK

Drop local QR code reading straight into your web app. Extract decoded text from uploaded images or live camera frames right inside the browser, while keeping full control of your UI and post-scan actions.

JavaScript
import init, { scan_image } from
  "@qrcode-ai-com/qrcode-barcode-scanner-wasm";

await init();
const bytes = new Uint8Array(await file.arrayBuffer());
const report = scan_image(
  bytes, "frame", undefined, undefined, 1000
);
const qr = report.detections
  .find(d => d.symbology === "qr_code");

console.log(qr?.content.text);

Inspect the decoded resulthttps://qrcode-ai.com/

Read a QR image

Let users pick a screenshot, saved image or mobile photo of a QR code. Receive the encoded text so your interface can display it or trigger the next step.

npm install @qrcode-ai-com/qrcode-barcode-scanner-wasm

Need to scan a code right away? Open online reader

Bring QR reading into your web app

Let users upload an image, scan through your own camera view and act on decoded content without leaving your web app.

Read a QR image

Let users pick a screenshot, saved image or mobile photo of a QR code. Receive the encoded text so your interface can display it or trigger the next step.

Read a camera frame

Send captured RGBA pixels to scan_frame, or wire up the package’s /camera controller and overlay while your app handles permissions.

Use the decoded content

Surface a URL, plain text or encoded WiFi credentials in your UI. Check the scan report for symbology and diagnostics before deciding what action to present.

Add QR image reading in JavaScript or TypeScript

Take a selected File and return its decoded QR text. Pick JavaScript or TypeScript for the exact same browser package.

Install the browser package

Install the browser WASM package on npm with your preferred package manager. The same MIT-licensed package reads QR codes (including Micro QR and rMQR) and barcodes, and is also hosted on jsDelivr, unpkg and esm.sh for no-bundler browser demos.

The browser WASM API reference covers every entry point, including /auto, /scan and /camera, while the open-source licensing guide sets out the MIT licence and third-party component notices. To test the scanner before installing anything locally, launch the Vite starter on StackBlitz or the interactive Hugging Face Space. The QR Code Scanner Examples show expected outputs and local setup steps.

npm install @qrcode-ai-com/qrcode-barcode-scanner-wasm

Read a QR image

Save the JavaScript or TypeScript snippet as your reader module and call readQrImage(file) from your file-input handler. Initialisation is cached once it succeeds and cleared on rejection so your app can run an explicit retry.

import init, { scan_image } from "@qrcode-ai-com/qrcode-barcode-scanner-wasm";

const WORK_BUDGET_MS = 1000;

let ready = null;
const prepareScanner = () => {
  ready ??= init().catch((error) => {
    ready = null;
    throw error;
  });
  return ready;
};

export const readQrImage = async (file) => {
  await prepareScanner();
  const bytes = new Uint8Array(await file.arrayBuffer());
  const report = scan_image(
    bytes, "frame", undefined, undefined, WORK_BUDGET_MS
  );
  return report.detections
    .filter((detection) => detection.symbology === "qr_code")
    .map((detection) => detection.content.text);
};

This example passes undefined for both image size limits, matching the scanner’s own browser example, so the engine defaults apply: 10,000 px per side and 64,000,000 pixels. A typical mobile phone photo, up to 48 megapixels, fits comfortably within these bounds. Images exceeding either cap are rejected with an input error (QRS-002 or QRS-003) rather than resized. For public-facing servers accepting untrusted uploads, pass tighter caps: the scanner docs use 4,096 px and 16,000,000 pixels. The 1,000 ms work budget is a setting, not an end-to-end latency guarantee.

The second argument, "frame", selects the scan profile. The frame profile decodes only; fast and full also compute the 0 to 100 QR scannability score. For named options such as formats: ["qr_code"] and an isFinal flag, use the /scan entry point (bindScanner).

Inspect the decoded result

A QR code image encoding https://qrcode-ai.com/ resolves to ["https://qrcode-ai.com/"]. Show that string in your interface; opening the link or triggering another workflow stays completely under your app’s control.

A blank image, or one containing only non-QR symbols such as a linear barcode, returns an empty array. An unreadable file or an image past the size caps throws an error instead: catch and handle it explicitly.

Compare JavaScript QR scanner APIs

Compare browser QR decoders: QR Code AI combines image and frame scanning with a /camera controller, 1D/2D barcode support and QR quality diagnostics.

Browser APIs · sources cited below · QR Code AI column updated 27 November 2026
CapabilityQR Code AIWASM · MITjsQRjsqrqr-scannerNimiqZXing Browser@zxing/browser

Image input

RGBA pixels

jsQR takes a Uint8ClampedArray of RGBA pixels together with width and height. Your app decodes a saved image or pulls pixel data from a camera frame first.

Image sources

QrScanner.scanImage accepts image, video and canvas elements, ImageBitmap, File/Blob and supported image URLs. Cross-origin URLs still require proper CORS headers.

Image sources

The browser layer exposes image-element, image-URL and canvas decoding methods. Pick either the QR reader or the multi-format reader to match your input.

Camera controls

App-managed

The jsQR README leaves platform camera capture up to the host app. Its webcam example reads ImageData from a canvas before calling the decoder.

Start / stop

For live camera scanning, the documented QrScanner API provides start(), stop() and destroy() around a video element. That trims boilerplate capture wiring compared with decoder-only APIs, while user permission is still required.

Capture / stop

For live camera scanning, decodeFromVideoDevice and decodeFromConstraints provide capture helpers plus controls.stop(). That reduces host capture wiring compared with decoder-only APIs, while camera permission is still required.

Returned data

Text + bytes

The documented result holds data, binaryData, chunks, version and location points. These cover decoded payload and geometry, not a documented scannability grade.

Text + corners

Using the documented detailed-result API, the response returns data and cornerPoints. The legacy string-only result stays on a separate compatibility path in this source revision.

Text + metadata

The result includes text, format, result points and format-specific metadata. Metadata such as error-correction level is not a QR scannability score.

QR diagnostics

Not described

The jsQR result documents data, binaryData, chunks, version and location. Its README does not describe any QR scannability score or hints.

Not described

The qr-scanner detailed result lists data and cornerPoints. Its documentation does not describe a QR scannability score or diagnostic hints.

Not described

ZXing Browser documentation does not describe a QR scannability score or hints. Format metadata and error-correction details are separate fields.

Green ticks indicate documented advantages for the stated criterion; plain text is neutral. “Not described” means the cited documentation does not mention that capability. Select underlined labels for full details. This comparison is not a speed or accuracy benchmark.

Sources: QR Code AI browser API, ScanReport specification, jsQR repository, Nimiq qr-scanner repository and ZXing Browser repository.

Build around your browser workflow

Camera and Web Workers. Pass RGBA pixels to scan_frame or integrate the /camera controller and overlay (check the browser camera sample script). Decode calls run synchronously, so execute scans inside a module Web Worker to keep the UI thread free; see the browser WASM API reference.

WASM loading and entry points. Exclude the package from Vite and Nuxt pre-bundling and set worker.format to "es" when using /auto inside Web Workers. Pick root init(), /auto (createScannerLoader(), SSR-safe), /scan (named formats plus isFinal) or /node for WASM in Node.js; full setup notes are in the WASM package setup guide.

Errors and on-device privacy. No code found returns an empty array; catch init() rejections as well as [QRS-001], [QRS-002] and [QRS-003] throws. The frame profile skips scoring (a null score is not zero). Once the assets load, decoding runs 100% locally on the user’s device.

QR Code Scanner browser API, reports and licence

These reference documents track the main branch of the scanner repository.

JavaScript QR scanner questions

Browser setup, TypeScript, Web Workers, camera capture, decoded output and licensing.

The JavaScript QR Code Scanner SDK is QR Code AI’s open-source MIT-licensed browser package for decoding QR codes from images and live camera frames inside your own web app. Published on npm as @qrcode-ai-com/qrcode-barcode-scanner-wasm, it is a WebAssembly build of the QR Code & Barcode Scanner engine that executes locally on the user’s device. Your app supplies the file or camera input, owns the interface and decides what happens next. See the QR Code Scanner SDK hub for other runtimes.

Yes. JavaScript and TypeScript share the same npm package. Its bundled declarations type scan_image, scan_frame and ScanReport out of the box. The TypeScript snippet simply adds File and return types around the same calls; no separate TypeScript package is required.

Yes. scan_image reads encoded image bytes, while scan_frame takes RGBA pixels along with width and height. The quickstart above decodes a selected File. For live camera scanning, the /camera entry point provides a capture controller and /camera-overlay renders the selection box. Your app still requests camera permission and decides when to stop scanning.

In Vite, add @qrcode-ai-com/qrcode-barcode-scanner-wasm to optimizeDeps.exclude so its WASM asset URL resolves properly, and set worker.format to "es" whenever a module Web Worker imports /auto. The Vite starter linked on QR Code Scanner Examples configures both. In Nuxt, place the same optimizeDeps.exclude entry inside the vite section of nuxt.config. Importing /auto is safe during SSR, but initialise the scanner and spawn the Web Worker strictly on the client, such as in a client-only component or mounted hook. Confirm that your production build serves the .wasm file under the actual deployment base path.

Each WASM decode call runs synchronously on whichever thread invokes it. Running decoding inside a Web Worker keeps heavy frame processing off the main UI thread. Your app remains responsible for loading, size caps, message passing and teardown. For live camera feeds, wait for the active scan to finish before dispatching the next frame; using a Web Worker does not by itself guarantee a specific frame rate or latency.

Both entry points load the same portable WASM module. The root entry point initialises it directly via init(). The /auto entry point exposes loadScanner() and createScannerLoader(), which inspect WebAssembly support first and return typed loading errors. Each loader memoises its single initialisation attempt, including any failure, so instantiate a new loader before retrying. An asset or security-policy error does not mean the browser lacks WebAssembly support.

The quickstart’s readQrImage(file) resolves to an empty array, [], whenever no QR code is detected. Because report.detections still holds every symbol the engine read, a barcode-only image yields a populated report alongside an empty QR list. Treat an empty result as final only when the work budget was not hit, meaning report.trace.budget_exhausted is false. Unreadable files or oversized images throw instead of returning []: the error message ends with [QRS-001] for unreadable input, or [QRS-002] / [QRS-003] when a size cap is exceeded. Loading failures reject init(). Wrap await readQrImage(file) in try/catch, clear any previous output and inform the user whether no QR code was found or the file was rejected.

Pick a profile based on image difficulty first, then whether you need quality scoring. The frame profile is the lightest: it decodes without scoring, leaving score as null. It works well for live camera frames and is used in the quickstart above for uploaded images. The fast and full profiles also compute the 0 to 100 QR scannability score and hints, with fast running at reduced depth and full running at maximum depth. full is the engine default and the only profile that runs the deepest pre-processing stage: if frame or fast misses a tricky image such as an artistic QR code, retry with full. A null score means no judgement, not zero. A work budget is not an end-to-end latency guarantee, and the score is a software diagnostic that does not certify printed labels or verify destination safety.

Yes. Once the package assets are loaded, browser decoding executes entirely on the device with no QR Code AI login or hosted decode API call. Your own app controls any uploads, telemetry, storage or outbound navigation. True offline use also requires caching the web app and its .wasm file; local decoding alone is not a blanket offline or site-wide privacy guarantee.

Yes. Current releases of the browser SDK ship under the MIT licence, which allows commercial and proprietary deployment, modification and redistribution provided copyright and licence notices are preserved. Check the open-source licensing guide for retained third-party notices and terms covering earlier releases.

No. Local browser decoding never requires a QR Code AI generation API key or consumes creation credits. SDK licensing is independent of the creation platform. On that platform, free creation caps and Premium apply only to QR creation features, not decoding; the seven-day Premium trial begins with your first dynamic QR code or Smart Link. Directly encoded data does not expire after the trial, though a managed destination may become unavailable and decoding cannot restore it.

Yes for barcodes, no for native Node.js. The exact same browser package, @qrcode-ai-com/qrcode-barcode-scanner-wasm, decodes both QR codes and barcodes, powering the JavaScript Barcode Scanner SDK as well. The snippet on this page filters detections to qr_code only. For server-side Node.js with native compiled speed, install @qrcode-ai-com/qrcode-barcode-scanner (or use this package’s /node entry point where native addons cannot run). Visit the QR Code Scanner SDK page to pick another runtime.