The issue with ngx-scanner not working on mobile is usually related to camera permissions, HTTPS, or browser compatibility. Here’s how to resolve it:
navigator.mediaDevices.getUserMedia({ video: true }).catch(err => console.log('Camera permission denied:', err));
HTTPS Required: Browsers block camera access on HTTP. Use HTTPS. Tools like ngrok
can expose your localhost over HTTPS.
iOS/Safari Issues: Add playsinline
to avoid fullscreen issues:
<zxing-scanner playsinline="true"></zxing-scanner>
getUserMedia
is supported: if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
console.error('getUserMedia is not supported on this device/browser.');
}
If you’re looking for a more reliable option, consider Scanbot SDK (disclaimer: I work for them). It offers broader device compatibility and runs in Angular. For an Angular integration quick guide, check out this tutorial.