From 111008a8586eadf7fa21e9ce1822fd96035852b0 Mon Sep 17 00:00:00 2001 From: Shawn Date: Mon, 1 Jun 2026 22:56:54 -0400 Subject: [PATCH] fix: ZXing per-frame 'no detection' errors were being treated as camera failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ZXing's decodeFromVideoDevice fires its callback on every video frame (~30fps). When no barcode is in view, it passes `(null, err)` where err is 'No MultiFormat Readers were able to detect the code' — this is NORMAL, not a hardware failure. The error branch now filters out 'multiformat' and 'unable to detect' messages, only calling handleCameraError for real device-level issues (permission denied, camera not found, stream broken). --- static/index.html | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/static/index.html b/static/index.html index bc620a7..d2b0fd8 100644 --- a/static/index.html +++ b/static/index.html @@ -2909,7 +2909,11 @@ } }, 5000); - // decodeFromVideoDevice handles camera + scanning in one call + // decodeFromVideoDevice handles camera + scanning in one call. + // The callback fires on every video frame (~30fps). ZXing passes + // "No MultiFormat Readers..." as an error when no barcode is in view + // — that's NORMAL, not a hardware failure. Only treat real device + // errors (permission denied, camera not found, stream broken) as fatal. codeReader.decodeFromVideoDevice(deviceId, video, (result, err) => { // Clear the timeout once we get any callback (stream started or error) clearTimeout(cameraFailTimer); @@ -2919,9 +2923,12 @@ handleBarcode(val.trim()); } } else if (err && scanningActive) { - // ZXing reports camera errors through the callback (not as exceptions) - console.error('ZXing camera error:', err); - handleCameraError(new Error(err.message || err)); + // Filter out "no barcode in frame" — that's normal, not a failure + const msg = (err.message || err || '').toLowerCase(); + if (!msg.includes('multiformat') && !msg.includes('unable to detect')) { + console.error('ZXing camera error:', err); + handleCameraError(new Error(err.message || err)); + } } }); } catch (e) {