qr-scanner is a JavaScript library designed for efficient QR code scanning from both continuous video streams (webcams) and static images. Currently at version 1.4.2, it appears to be actively maintained, supported by Nimiq, and offers significant performance and accuracy advantages over older libraries like LazarSoft/jsqrcode, boasting a 2-8x higher detection rate and fewer misreads according to benchmarks. Key differentiators include its lightweight footprint (as low as 5.6 kB gzipped when `BarcodeDetector` is available), automatic utilization of the browser's native `BarcodeDetector` API for optimal performance, and its design to run in a WebWorker to keep the main UI thread responsive. The library is built upon Cosmo Wolfe's JavaScript port of Google's ZXing library, with several improvements geared towards modern web environments and optimized for colored QR codes.
npm install qr-scannerVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to set up `qr-scanner` to read QR codes from a live webcam feed in a browser environment, displaying the result on the page. It highlights the essential worker script configuration.
Ensure `qr-scanner-worker.min.js` is in your public assets directory and set `QrScanner.workerScript = 'path/to/qr-scanner-worker.min.js';` before initializing `QrScanner`. For bundlers, consult your bundler's documentation on how to handle web worker scripts or static assets.
For CommonJS environments or older build setups, explicitly use `require('qr-scanner/qr-scanner.umd.min.js')`. For modern browser usage or bundlers, use `import QrScanner from 'qr-scanner';` within a `<script type="module">` or an ES module-aware bundler setup.Integrate a JavaScript transpiler like Babel into your build pipeline and configure it to target older browsers with necessary polyfills for ES2017 features.
Inform users that performance might differ across browsers. No direct 'fix' other than using a modern browser. You can check `window.BarcodeDetector` for its availability if you need to provide browser-specific UI/UX hints.
Change your `<script>` tag to `<script type="module">` or load the UMD build (`qr-scanner.umd.min.js`) directly via a standard `<script>` tag, which exposes `QrScanner` globally.
Verify that `qr-scanner-worker.min.js` is physically located in your public assets directory, that `QrScanner.workerScript` is set to the correct URL relative to your HTML page or domain root, and that your web server serves `.js` files with the `application/javascript` MIME type.
Ensure you are using the correct import strategy for your environment: `import QrScanner from 'qr-scanner';` for ES Modules (with bundler), `import QrScanner from './path/to/qr-scanner.min.js';` for plain browser ES Modules, or `const QrScanner = require('qr-scanner/qr-scanner.umd.min.js');` for CommonJS.No dependency data recorded yet.