browser
browser copied to clipboard
BUG: Missing await causes an uncaught exception
controls.stop
This line is missing an await when calling switchTorch, so if it fails theres no way to capture the error in a try catch.
https://github.com/zxing-js/browser/blob/9e0ef5e4a661a5989a9b4a97117a20b1fcd4527d/src/readers/BrowserCodeReader.ts#L755
I also have this issue with "setPhotoOptions" on Android after calling stop. Problem is not only with missing await, but also that it tries to turn off torch when it was not used at all.
I was able to "fix" this error by this hack:
const mediaStreamSetTorch = BrowserCodeReader.mediaStreamSetTorch;
BrowserCodeReader.mediaStreamSetTorch = async (track, onOff) => {
try {
await mediaStreamSetTorch(track, onOff);
} catch (err) {
console.error(err);
}
};
Or if you don't need the torch at all:
BrowserCodeReader.mediaStreamSetTorch = async () => {};