zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.
https://zxing-js.github.io/library/
Apache License 2.0
2.5k stars 546 forks source link

How to handle errors from the BrowserMultiFormatReader? #624

Open Laurenz-M opened 3 weeks ago

Laurenz-M commented 3 weeks ago

I'm having trouble to receive any errors or results in the callback of "decodeFromVideoDevice". This is a simplification of my code: const reader = new BrowserMultiFormatReader(); const deviceId = '[valid device id here]' reader.decodeFromVideoDevice(deviceId, 'video', (result, err) => { console.log('test', err); if (!result) return; }) The whole code works, when the camera does not emit any errors and i can successfully scan items.

My issue is with the error-handling, as the console log with "test" does never trigger, when there is an error. To test this, I triggered errors for "NotAllowedError: Permission denied", "NotAllowedError: Permission dismissed" and "NotReadableError: Device in use", which are all correctly recognized and logged in the console by the library code itself, but are not returned in the error callback.

My understanding is that the errors happen before the actual initialization and are this not returned.

It would be great if someone could assist me in this matter. Thanks a lot! :)

Screenshot 2024-10-28 120909