ℹ️ QR Code reading runs entirely client-side using the jsQR library. No server API is needed.
Decode QR codes from image data using the jsQR library (works in Node.js and browsers).
// Install: npm install jsqr
// Browser CDN: https://cdn.jsdelivr.net/npm/jsqr@1.4.0/dist/jsQR.min.js
// Read from a canvas element:
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const code = jsQR(imageData.data, imageData.width, imageData.height);
if (code) {
console.log("Decoded:", code.data);
// → "https://example.com"
}
// Read from camera (MediaDevices API):
const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'environment' } });
const video = document.createElement('video');
video.srcObject = stream;
video.play();
// Then draw video frames to canvas and scan with jsQR