JavaScript Barcode Scanner SDK

Read barcode images or live camera frames in your web app. Get each identifier and its format for your stock or inventory workflow, decoded on the user’s device.

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 barcode = report.detections
  .find(d => d.symbology === "code128");

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

Inspect the decoded resultSTOCK-4827

Read a barcode image

Let users select a label photo, screenshot or saved image. A Code 128 label containing STOCK-4827 returns that exact reference for your interface to display or use.

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

Want to scan a barcode now? Open the online reader

Bring barcode reading into your web app

Let users capture a label, see its decoded identifier and continue in your own interface.

Read a barcode image

Let users select a label photo, screenshot or saved image. A Code 128 label containing STOCK-4827 returns that exact reference for your interface to display or use.

Read a camera frame

Pass captured RGBA pixels to scan_frame, or use the /camera controller and overlay while your app owns permissions.

Use the identifier and format

Use the decoded text and symbology to query your database. Keep identifiers as strings so leading zeros survive.

Read a barcode image in JavaScript or TypeScript

Pass a selected File and receive identifier strings with their detected formats. Choose JavaScript or TypeScript for the same browser package.

Install the browser package

Choose a package manager for the browser package on npm. The same MIT-licensed package reads 1D and 2D barcodes and QR codes, and is also served on jsDelivr, unpkg and esm.sh for browser demos without a bundler.

The browser API documents every entry point, including /auto, /scan and /camera, and the licensing guide explains the MIT licence and component notices. To try the scanner before installing anything, open the Vite example in StackBlitz or the Hugging Face Space. The Barcode Scanner examples show what it returns and how to run it on your machine.

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

Read a selected label image

Save the JavaScript or TypeScript version as your reader module and call readBarcodeImage(file) from your file-input flow. Initialisation is shared after success and cleared after rejection so an explicit retry can run. The function keeps eight common formats (Code 128, Code 39, EAN-13, EAN-8, UPC-A, UPC-E, ITF and Data Matrix) and filters out everything else, including QR codes. Add other identifiers to BARCODE_FORMATS when your labels need them.

To test your file-input flow, create a test barcode with Barcode Generator using Code 128 and STOCK-4827, then select its PNG in your app and check the returned symbology (the format identifier, here code128) and text.

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

const BARCODE_FORMATS = new Set([
  "code128", "code39", "ean13", "ean8",
  "upc_a", "upc_e", "itf", "data_matrix"
]);
const WORK_BUDGET_MS = 1000;

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

export const readBarcodeImage = 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) => BARCODE_FORMATS.has(detection.symbology))
    .map((detection) => ({
      symbology: detection.symbology,
      text: detection.content.text
    }));
};

The example passes undefined for the two image size limits, as the scanner’s own browser example does, so the engine’s defaults apply: 10,000 px per side and 64,000,000 pixels. An ordinary mobile phone photo of a label, up to 48 megapixels, stays within them. An image above either limit is refused with an input error (QRS-002 or QRS-003): it is not resized. On a server that accepts images from the public, pass lower limits: the scanner’s documentation uses 4,096 px and 16,000,000 pixels. The 1,000 ms work budget is a setting, not an end-to-end latency guarantee. These synchronous decode calls belong in a Web Worker when your interface must stay responsive.

The second argument, "frame", is the scan profile. The frame profile is the lightest: it only decodes. The fast and full profiles also compute a scannability score for the first code of the report, fast at reduced depth and full at full depth. To restrict decoding inside the engine itself and receive an isFinal flag, use the /scan entry (bindScanner) with a formats list.

Inspect the decoded result

For a Code 128 image containing STOCK-4827, the function returns one result with symbology code128 and text STOCK-4827. A UPC-A example returns 012345678905 as a string, including its leading zero. Display that value or use it as your database lookup key.

A blank image or one containing only QR codes returns an empty array. An unreadable file, an image above the size limits or an initialisation failure makes the call throw: catch it.

Compare JavaScript barcode scanner APIs

Compare browser barcode libraries across 1D labels, Data Matrix and built-in camera helpers; product lookup stays in your app.

Browser APIs · sources listed below · QR Code AI column updated 27 November 2026
CapabilityQR Code AIWASM · MITZXing Browser@zxing/browserQuagga2@ericblade/quagga2html5-qrcodehtml5-qrcode

Barcode formats

1D + 2D

Select a suitable ZXing reader: the multi-format reader covers 1D and 2D, with a dedicated Data Matrix reader also documented. Coverage is reader-dependent. For a workflow that also needs Data Matrix, this is a documented coverage advantage over the cited Quagga2 built-in 1D readers.

Built-in 1D

The cited built-in readers include Code 128, EAN, UPC, Code 39 and other linear formats. External readers are outside this comparison.

1D + Data Matrix

The cited supported-format list includes Code 128, EAN, UPC and Data Matrix among other formats. Enabled formats and backend configuration must match the intended workflow. For a workflow that also needs Data Matrix, this is a documented coverage advantage over the cited Quagga2 built-in 1D readers.

Image input

Image sources

ZXing Browser provides image-element, image-URL and canvas decoding methods with a reader appropriate to the required symbologies.

Image callback

Quagga.decodeSingle processes a single saved image and returns its result through a callback. Image-size and decoder configuration still matter.

Local File

Html5Qrcode.scanFile and scanFileV2 process a local File. This is distinct from the optional end-to-end camera scanner UI.

Camera controls

Capture / stop

The browser layer supplies capture methods and stop controls, which reduces application camera and lifecycle wiring. Camera permission and a user-facing flow are still needed.

Start / stop

Quagga.start() starts video processing and Quagga.stop() stops decoding and disconnects a requested camera stream.

Start / stop

The low-level Html5Qrcode API manages camera scanning; Html5QrcodeScanner adds an optional ready-made interface. Permission is still required.

Returned data

Text + metadata

Results contain decoded text, barcode format, points and format-dependent metadata. Product lookup still requires the application’s data source.

Text + location

The documented result includes codeResult.code and format plus localisation and decoder data. Keep identifiers as strings; this is not a product record.

Text + format

The scan callback returns decoded text and a result describing the detected format. Product names, retail prices and stock levels require a separate lookup.

Green ticks mark documented advantages for workflows that mix 1D and 2D labels; plain text is neutral, including the camera helpers that all four libraries document. Open underlined labels for details. The cited html5-qrcode revision reports maintenance mode. This table is not a speed, accuracy or print-quality benchmark.

Sources: QR Code AI browser API, report specification, ZXing Browser, ZXing formats, Quagga2, html5-qrcode and its File and camera APIs.

Connect barcode decoding to your application

Camera and Web Workers. Pass RGBA pixels to scan_frame or use the /camera controller (see the camera example). Run synchronous scans inside a module Web Worker off the UI thread; see the browser API.

WASM loading and entry points. Exclude the package from Vite/Nuxt pre-bundling (worker.format: "es" for /auto in Web Workers) and run scanning client-side only. Choose root init(), /auto (createScannerLoader()), /scan (formats, isFinal) or /node; see the package setup guide.

Identifiers, errors and privacy. Keep values as strings so leading zeros survive (ISBN → ean13, GS1-128 → code128, ITF-14 → itf). Empty arrays mean no barcode; catch init() rejections and [QRS-001]/[QRS-002]/[QRS-003] throws. Decoding runs 100% locally after load.

JavaScript barcode scanner questions

Browser setup, TypeScript, label formats, identifiers, camera input and licensing.

The JavaScript Barcode Scanner SDK is QR Code AI’s open-source MIT browser package for reading 1D and 2D barcodes from images and camera frames inside your own web app. It is published on npm as @qrcode-ai-com/qrcode-barcode-scanner-wasm, a WebAssembly build of the QR Code & Barcode Scanner engine, and it decodes on the user’s device. Your application receives each identifier with its detected format, then decides how to use them. The Barcode Scanner SDK page covers other environments.

Yes. JavaScript and TypeScript use the same browser package. Its declarations include scan_image, scan_frame and ScanReport. The TypeScript example adds File and result types around the same decoding calls. It returns identifier strings plus symbology; it does not need a separately named TypeScript package.

The quickstart’s readBarcodeImage(file) keeps eight formats: Code 128, Code 39, EAN-13, EAN-8, UPC-A, UPC-E, ITF and Data Matrix. ISBN, GS1-128 and ITF-14 labels return the underlying EAN-13, Code 128 and ITF symbologies. The package also reads Code 93, Codabar, GS1 DataBar, GS1 DataBar Expanded, Telepen, PDF417, Aztec and MaxiCode. To keep them, add their identifiers to BARCODE_FORMATS: code93, codabar, data_bar, data_bar_expanded, telepen, pdf417, aztec and maxi_code.

Yes. scan_image accepts encoded image bytes; scan_frame accepts RGBA pixels, width and height. The quickstart handles a selected File. For live capture, the /camera entry adds a capture controller and the /camera-overlay entry draws the selection. Your app still requests camera permission and decides when scanning stops.

No. The scanner returns the encoded identifier and its detected format. A product name, retail price or stock level comes from a separate database that your application queries. Keep identifiers as strings, preserve leading zeros and send the value in the form that database expects. Decoding does not prove which product a code belongs to or that a label is genuine.

In your Vite config, add @qrcode-ai-com/qrcode-barcode-scanner-wasm to optimizeDeps.exclude so its WASM URL resolves, and set worker.format to "es" when a module Web Worker imports the /auto entry. The Vite example on the Barcode Scanner examples page sets both. In Nuxt, put the same optimizeDeps.exclude entry under the vite key of your Nuxt config, then construct Web Workers and run scanning in the browser, such as from a mounted feature or client-only component. Confirm that the built app serves the .wasm file under its actual deployment base path.

The WASM scan call is synchronous on its calling thread. A Web Worker moves decoding away from the main interface thread. Your application still handles loading, inputs, errors, result messages and disposal. For camera capture, finish one scan before scheduling another; moving work to a Web Worker does not guarantee a frame rate or response time.

Both load the same portable WASM module. The root entry initialises it with init(). The /auto entry exposes loadScanner() and createScannerLoader(), which check WebAssembly features first and report typed loading errors. One loader memoises a single initialisation attempt, including failure. Create a new loader for an explicit retry; a network or asset-policy error does not prove a missing browser feature.

The quickstart’s readBarcodeImage(file) returns an empty array, [], when the image holds none of the formats it keeps. A QR-only image therefore gives an empty barcode result, even though the scan report lists the QR code in report.detections. An empty result is final only when the scan was not cut by its work budget: report.trace.budget_exhausted is then false. A file that is not a readable image, or an image above the size limits, does not return []: the call throws an error whose message ends with its code, [QRS-001] for an unreadable file, [QRS-002] or [QRS-003] for an image above a size limit. A loading failure makes init() reject. Wrap await readBarcodeImage(file) in try/catch, and clear the previous identifier so a stale reading is not shown as a new result.

Yes. After the package files load, decoding runs on the device without a QR Code AI login or hosted decoding request. Your application determines uploads, telemetry, storage, product lookups and other network requests. Offline operation additionally requires delivering and caching the app and WASM files; local decoding alone is not an offline or site-wide privacy guarantee.

Yes. Current releases of the browser SDK are published under the MIT licence, which permits use, modification and redistribution in both open-source and proprietary commercial applications while preserving the copyright and licence notices. Review the licensing guide for retained third-party notices and the terms shipped with earlier versions.

No. Local decoding does not require a QR Code AI generation API key or consume creation credits. SDK licensing is separate from the creation platform’s free limits and Premium features. On that platform, the seven-day Premium trial begins with the first dynamic QR code or Smart Link, not barcode scanning or barcode creation. After the trial, Premium is required to keep using dynamic QR codes and Smart Links. Directly encoded barcode values remain in the symbol after that trial.

Yes for QR codes, no for native Node.js. The browser package is the same for barcodes and QR codes: @qrcode-ai-com/qrcode-barcode-scanner-wasm reads both. This guide keeps barcode detections in its example, and the QR JavaScript guide keeps QR detections. For server-side Node.js with native performance, use @qrcode-ai-com/qrcode-barcode-scanner (or use this package’s /node entry when native addons cannot run). Visit the Barcode Scanner SDK page for another environment.