From 8cc563374df12c4db093a1883a1b9e27fabba7dd Mon Sep 17 00:00:00 2001 From: Shawn Date: Wed, 20 May 2026 15:32:44 -0400 Subject: [PATCH] fix: call listVideoInputDevices on reader instance, not static ZXing.BrowserMultiFormatReader.listVideoInputDevices is an instance method, not a static method. Call codeReader.listVideoInputDevices() after creating the reader. Also wrap in try/catch with null fallback so decodeFromVideoDevice picks the default camera if enumeration fails. --- static/index.html | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/static/index.html b/static/index.html index d5903e7..cdfecda 100644 --- a/static/index.html +++ b/static/index.html @@ -2613,20 +2613,25 @@ // Create reader with 1D-only hints for fast, accurate scanning codeReader = new ZXing.BrowserMultiFormatReader(_barcodeHints(), _barcodeOptions()); + // Pick the rear-facing camera (environment-facing on phones) + let deviceId = null; + try { + const devices = await codeReader.listVideoInputDevices(); + if (devices && devices.length > 0) { + const rear = devices.find(d => + d.label && /back|rear|environment/i.test(d.label) + ); + deviceId = rear ? rear.deviceId : devices[0].deviceId; + } + } catch (e) { + // Fallback: pass null to let decodeFromVideoDevice pick default + console.warn('listVideoInputDevices failed, using default camera:', e); + } + document.getElementById('cameraPlaceholder').style.display = 'none'; video.style.display = 'block'; scanningActive = true; - // Pick the rear-facing camera (environment-facing on phones) - const devices = await ZXing.BrowserMultiFormatReader.listVideoInputDevices(); - let deviceId = null; - if (devices && devices.length > 0) { - const rear = devices.find(d => - d.label && /back|rear|environment/i.test(d.label) - ); - deviceId = rear ? rear.deviceId : devices[0].deviceId; - } - setScanStatus('Point camera at a barcode', 'success'); // decodeFromVideoDevice handles camera + scanning in one call