He estado tratando de implementar un lector de código de barras en mi página web alojada en localhost iis.
La biblioteca que estoy usando es: <script type="text/javascript" src="https://unpkg.com/@@zxing/library@latest"></script>
Mi código es:
const codeReader = new ZXing.BrowserMultiFormatReader();
codeReader.decodeFromVideoDevice(undefined, 'webcam-preview', (result, err) => { if (result) { // properly decoded qr code console.log('Found QR code!', result) document.getElementById('result').textContent = result.text } if (err) { // As long as this error belongs into one of the following categories // the code reader is going to continue as excepted. Any other error // will stop the decoding loop. // // Excepted Exceptions: // // - NotFoundException // - ChecksumException // - FormatException if (err instanceof ZXing.NotFoundException) { console.log('No QR code found.') } if (err instanceof ZXing.ChecksumException) { console.log('A code was found, but it\'s read value was not valid.') } if (err instanceof ZXing.FormatException) { console.log('A code was found, but it was in a invalid format.') } } })Mi lector de código de barras funciona en el navegador de escritorio 'chrome', pero no abre la cámara en ningún navegador móvil. He probado Chrome, Firefox, Opera.
Cuando compruebo desde chrome://inspect
Recibo este error del dev. consola
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'getUserMedia') at t.BrowserMultiFormatReader.<anonymous> (library@latest:15:29847) at Generator.next (<anonymous>) at library@latest:15:27264 at new Promise (<anonymous>) at P (library@latest:15:27009) at t.BrowserMultiFormatReader.decodeFromConstraints (library@latest:15:29776) at t.BrowserMultiFormatReader.<anonymous> (library@latest:15:29708) at Generator.next (<anonymous>) at library@latest:15:27264 at new Promise (<anonymous>)Probando en Chrome 98.0.4758.87
Samsung Galaxy S10+ Android 12
Pensé que el problema puede deberse a que estoy usando http, no https en localhost. Pero no estoy seguro.
¿Algunas ideas?
Gracias por adelantado.