zxing-js / browser

ZXing for JS's browser layer with decoding implementations for browser.
MIT License
222 stars 44 forks source link

Silent failure when passing DecodeHintType.TRY_HARDER to BrowserMultiFormatOneDReader #74

Open toondkn opened 3 years ago

toondkn commented 3 years ago

Library works great! Really easy way to get started with scanning 1D/2D codes in the browser.

I wanted to try out the DecodeHintType.TRY_HARDER hint to improve the result accuracy with the following code:

const hintMap = new Map();
hintMap.set(DecodeHintType.TRY_HARDER, true);
const codeReader = new BrowserMultiFormatOneDReader(hintMap);
const decode = codeReader.decodeFromVideoDevice(undefined, videoElement, handleResultFn);

However this fails silently. No errors in the console. The video element never shows any video and the browser disconnects from the webcam a few seconds after giving it permission. This happens in Chromium 98.0.4694.0 as well as Safari 15.1.

Passing other hints works just fine. It is specifically the TRY_HARDER hint that causes a silent failure.

ale-cci commented 2 years ago

i have the same problem, the view crashes with Error: Could not create a Canvas element..

At first glance it seems that the cause is tempCanvasElement = null missing in the constructor of the transpiled HTMLCanvasElementLuminanceSource