How the QR Code Reader Decodes
AnyTool QR Code Reader works two ways, both entirely in the browser. For live scanning it calls navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } }) to open a back-facing camera into a muted, playsInline video element, then runs a requestAnimationFrame loop that draws each frame to an offscreen canvas, reads the pixels with getImageData and decodes them. For image decoding it draws a dropped, pasted or uploaded picture to the same canvas and decodes it once. Decoding tries the native BarcodeDetector API first — new BarcodeDetector({ formats: ['qr_code'] }).detect(source) — which is hardware-accelerated in Chromium-based browsers and on Android, and falls back to jsQR, a tiny pure-JavaScript decoder lazily imported into its own chunk, in browsers that do not ship the API (notably Firefox and Safari). On a hit it draws the detected code’s location box over the preview and optionally plays a short WebAudio beep.
- Camera: getUserMedia → video → canvas → getImageData → decode in a rAF loop
- Image: dropped, pasted or uploaded picture decoded once on a canvas
- Native BarcodeDetector (Chromium / Android) with a jsQR fallback everywhere
- jsQR is lazily imported into its own chunk, so it is not in the app shell
- Detected code is outlined on the preview; an optional beep confirms a scan
