@zxing/library, html5-qrcode, jsqr, qr-scanner, and qrcode-reader are JavaScript libraries that enable QR code detection and decoding directly in the browser using device cameras or image inputs. These packages vary significantly in scope, API design, performance characteristics, and maintenance status. While some provide full-featured camera integration with real-time scanning, others focus solely on decoding raw pixel data from images or video frames, requiring developers to handle media setup manually.
When you need to scan QR codes in a web app, you have several libraries to choose from β but they differ dramatically in what they do, how much work they save you, and whether theyβre still maintained. Letβs cut through the noise and compare the real engineering trade-offs.
qrcode-readerFirst, the easy decision: qrcode-reader is deprecated. Its npm page states itβs no longer maintained, and the GitHub repo hasnβt seen updates in years. Donβt use it in new projects. Weβll include it in comparisons only for completeness, but treat it as obsolete.
The biggest split among these libraries is whether they handle the entire scanning flow (camera access, UI, real-time decoding) or just the decoding step (turning pixel data into text).
html5-qrcode and qr-scannerThese packages manage everything:
html5-qrcode example:
import { Html5Qrcode } from "html5-qrcode";
const html5QrCode = new Html5Qrcode("reader");
html5QrCode.start(
{ facingMode: "environment" },
{ fps: 10, qrbox: { width: 250, height: 250 } },
(decodedText) => console.log("Found:", decodedText),
(errorMessage) => console.log("Error:", errorMessage)
);
qr-scanner example:
import QrScanner from "qr-scanner";
import QrFrame from "qr-scanner/qr-scanner.min.js";
const video = document.getElementById("video");
const scanner = new QrScanner(video, result => console.log(result));
scanner.start();
Note:
qr-scannerrequires you to include its worker script separately for optimal performance.
@zxing/library and jsqrThese expect you to provide raw image data (e.g., from a <canvas> or <video> frame). You handle camera setup, frame capture, and retry logic.
jsqr example:
import jsQR from "jsqr";
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
// Assume video is already streaming
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const code = jsQR(imageData.data, imageData.width, imageData.height);
if (code) console.log("Found:", code.data);
@zxing/library example:
import { BrowserMultiFormatReader } from "@zxing/library";
const codeReader = new BrowserMultiFormatReader();
const video = document.querySelector("video");
// Start decoding from video stream
const controls = await codeReader.decodeFromVideoDevice(
null,
video,
(result, error, controls) => {
if (result) console.log("Found:", result.getText());
}
);
@zxing/librarydoes offer high-level camera helpers (decodeFromVideoDevice), but theyβre less polished thanhtml5-qrcodeβs API.
jsqr runs entirely in the main thread. For smooth UI, you must throttle frame analysis (e.g., using requestAnimationFrame with skips).qr-scanner uses a Web Worker by default to avoid blocking the UI β a big plus for responsive apps.@zxing/library can be heavy because it supports many barcode formats; QR-only decoding is possible but not the default.html5-qrcode runs decoding on the main thread but lets you limit FPS to reduce load.Need to tweak the scanning region, add overlays, or handle multiple concurrent scans?
jsqr gives maximum control β you decide exactly which pixels to analyze and when.qr-scanner allows customizing the scan region and includes a built-in highlight box.html5-qrcode lets you configure the scan area (qrbox) but offers less visual customization.@zxing/library requires manual DOM manipulation for overlays but supports advanced decoding hints.All camera-enabled libraries must handle getUserMedia() permissions, but their approaches differ:
html5-qrcode includes built-in error messages for common issues (e.g., camera not found).qr-scanner throws clear errors but leaves UI feedback to you.@zxing/library propagates raw DOMExceptions β youβll need to map them to user-friendly messages.What if you want to scan from an uploaded image, not a camera?
html5-qrcode:
Html5Qrcode.scanFile(file).then(text => console.log(text));
qr-scanner:
QrScanner.scanImage(fileOrUrl).then(result => console.log(result));
jsqr and @zxing/library require you to draw the image to a canvas first, then extract pixel data β more code, but more flexible.
html5-qrcode uses separate success/error callbacks.qr-scanner returns promises that reject on errors.jsqr returns null on failure β no exceptions thrown.@zxing/library throws errors during decoding, which you must catch in your callback.| Library | Camera Built-in? | Worker Support? | File Scanning? | Multi-Format? | Actively Maintained? |
|---|---|---|---|---|---|
@zxing/library | Partial | β | Manual | β | β |
html5-qrcode | β | β | β | QR only | β |
jsqr | β | β | Manual | QR only | β |
qr-scanner | β | β | β | QR only | β |
qrcode-reader | β | β | Manual | QR only | β (Deprecated) |
html5-qrcode. Itβs the quickest path to a working demo.qr-scanner with its worker-based decoding.jsqr for pixel-level control.@zxing/library.qrcode-reader.Choose based on whether you value convenience (html5-qrcode, qr-scanner) or control (jsqr, @zxing/library). And always check the official docs β APIs evolve, and assumptions can break.
Choose jsqr if you're building a custom scanning pipeline and only need a lightweight, dependency-free decoder for static images or pre-captured video frames. It gives you complete control over the media input and processing loop but requires you to implement camera access, frame extraction, and scanning logic yourself. Perfect for performance-critical or highly customized scanning scenarios.
Choose html5-qrcode if you want a simple, all-in-one solution for real-time QR scanning from a webcam with minimal setup. It handles camera enumeration, permission requests, UI rendering, and decoding out of the box, making it ideal for quick integrations where developer experience and ease of use are prioritized over fine-grained control.
Choose qr-scanner if you need a balance between ease of use and performance, with built-in camera support and optional worker-based decoding for better responsiveness. It offers a clean API for both file and camera scanning, includes a highlight overlay for detected codes, and allows disabling worker usage if needed. A solid middle-ground choice for most web apps.
Do not choose qrcode-reader for new projects β it is officially deprecated according to its npm page and GitHub repository. The package has not been updated in years and lacks modern features like camera integration or performance optimizations. Use one of the actively maintained alternatives instead.
Choose @zxing/library if you need a mature, multi-format barcode/QR scanning solution that supports not just QR codes but also many 1D and 2D barcode formats. It provides both low-level decoding APIs and higher-level continuous scanning capabilities, though it requires more manual setup for camera handling compared to turnkey solutions. Best suited for applications requiring broad symbology support beyond QR codes.
A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
Available on npm. Can be used in a Node.js program or with a module bundler such as Webpack or Browserify.
npm install jsqr --save
// ES6 import
import jsQR from "jsqr";
// CommonJS require
const jsQR = require("jsqr");
jsQR(...);
Alternatively for frontend use jsQR.js can be included with a script tag
<script src="jsQR.js"></script>
<script>
jsQR(...);
</script>
jsQR is designed to be a completely standalone library for scanning QR codes. By design it does not include any platform specific code. This allows it to just as easily scan a frontend webcam stream, a user uploaded image, or be used as part of a backend Node.js process.
If you want to use jsQR to scan a webcam stream you'll need to extract the ImageData from the video stream. This can then be passed to jsQR. The jsQR demo contains a barebones implementation of webcam scanning that can be used as a starting point and customized for your needs. For more advanced questions you can refer to the getUserMedia docs or the fairly comprehensive webRTC sample code, both of which are great resources for consuming a webcam stream.
jsQR exports a method that takes in 3 arguments representing the image data you wish to decode. Additionally can take an options object to further configure scanning behavior.
const code = jsQR(imageData, width, height, options?);
if (code) {
console.log("Found QR code", code);
}
imageData - An Uint8ClampedArray of RGBA pixel values in the form [r0, g0, b0, a0, r1, g1, b1, a1, ...].
As such the length of this array should be 4 * width * height.
This data is in the same form as the ImageData interface, and it's also commonly returned by node modules for reading images.width - The width of the image you wish to decode.height - The height of the image you wish to decode.options (optional) - Additional options.
inversionAttempts - (attemptBoth (default), dontInvert, onlyInvert, or invertFirst) - Should jsQR attempt to invert the image to find QR codes with white modules on black backgrounds instead of the black modules on white background. This option defaults to attemptBoth for backwards compatibility but causes a ~50% performance hit, and will probably be default to dontInvert in future versions.If a QR is able to be decoded the library will return an object with the following keys.
binaryData - Uint8ClampedArray - The raw bytes of the QR code.data - The string version of the QR code data.chunks - The QR chunks.version - The QR version.location - An object with keys describing key points of the QR code. Each key is a point of the form {x: number, y: number}.
Has points for the following locations.
topRightCorner/topLeftCorner/bottomRightCorner/bottomLeftCorner;topRightFinderPattern/topLeftFinderPattern/bottomLeftFinderPatternbottomRightAlignmentPattern assuming one exists and can be located.Because the library is written in typescript you can also view the type definitions to understand the API.
jsQR is written using typescript.
You can view the development source in the src directory.
Tests can be run with
npm test
Besides unit tests the test suite contains several hundred images that can be found in the /tests/end-to-end/ folder.
Not all the images can be read. In general changes should hope to increase the number of images that read. However due to the nature of computer vision some changes may cause images that pass to start to fail and visa versa. To update the expected outcomes run npm run-script generate-test-data. These outcomes can be evaluated in the context of a PR to determine if a change improves or harms the overall ability of the library to read QR codes. A summary of which are passing
and failing can be found at /tests/end-to-end/report.json
After testing any changes, you can compile the production version by running
npm run-script build
Pull requests are welcome! Please create seperate branches for seperate features/patches.