These packages range from pixel decoders to browser camera controllers and scanner interfaces. Choose required code formats, input source and UI responsibility before comparing them as QR scanning libraries.
jsqr takes RGBA pixel data, width and height. The byte array is a Uint8ClampedArray with four entries per pixel. It returns decoded QR information or null when no code is found. The application supplies image loading, camera frames and the scanning loop. It is a decoder rather than an out-of-the-box camera widget.
qrcode-reader uses an instance and callback-style decoding. In Node.js, its examples first decode an image into bitmap data with a separate image library; a compressed image file is not automatically equivalent to RGBA pixels. Browser image inputs and canvas data have their own documented overloads. The callback result and the raw input contract differ from jsqr; neither package supplies a complete camera UI merely by decoding an image.
qr-scanner supplies camera scanning around a video element, plus scanImage for still images. start, stop and destroy are distinct lifecycle operations; a destroyed instance cannot simply be resumed. Its documented detailed-result option changes the callback result contract, so match the handler to the selected options. It uses native BarcodeDetector where available and a worker fallback; make the worker file resolvable when the bundler does not handle its dynamic import. Still-image failure is an error path, not an empty successful result.
html5-qrcode offers Html5QrcodeScanner for an integrated scanner interface and Html5Qrcode for building a custom UI around camera and file APIs. It supports more than QR codes, subject to its supported-format configuration. Camera setup, file scanning and UI cleanup are different operations. Select the interface according to how much of the screen and lifecycle the application wants to own.
@zxing/library exposes multi-format readers and writers, including QR and other barcode families. Its published entry also re-exports browser interfaces; do not remove those capabilities just because another package offers a more specialized camera wrapper. The current manifest declares Node >=24, which matters for Node-based use and installation policy; browser deployment has a separate environment. Its README states that the maintainers do not have time for active maintenance and welcome new maintainers. Account for that stated availability without calling it an npm deprecation or a nonfunctional package.
For QR-only camera capture, a focused scanner may reduce application glue. For multiple barcode families, inspect the required reader and the chosen browser interface. For an existing image pipeline, a pixel decoder can be sufficient. Validate representative image inputs, result shapes and teardown behavior in the application; the availability of a camera or a successful image load does not itself mean a code was decoded.
Choose when you already have RGBA image data and want a QR decoder without a bundled camera or scanner UI.
Choose for ZXing-derived multi-format decoding and its published reader interfaces, after accounting for current runtime declarations and the project’s stated maintenance availability.
Choose for a browser scanner with a ready-made UI or its lower-level camera and file-scanning APIs.
Choose for a browser QR workflow with camera lifecycle methods and still-image scanning, including its documented worker-loading setup.
Choose for an existing callback-oriented QR image-decoding integration that supplies the required image data or browser image input.
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.