browser icon indicating copy to clipboard operation
browser copied to clipboard

BUG: Missing await causes an uncaught exception

Open ddoice opened this issue 2 years ago • 2 comments

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

image

ddoice avatar Jun 07 '23 15:06 ddoice

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.

Somnium7 avatar Jan 29 '24 11:01 Somnium7

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 () => {};

klangenk avatar Sep 16 '24 19:09 klangenk