cozmo / jsQR

A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
https://cozmo.github.io/jsQR/
Apache License 2.0
3.63k stars 600 forks source link

iOS Safari freezes #157

Open lucakermas opened 4 years ago

lucakermas commented 4 years ago

After some seconds jsQR keeps on getting the following error: array size is not a small enough positive integer

This is only happening on my iPhone with Safari. It does this on the demo, too.

Zitus commented 4 years ago

Was this error corrected?

zspitzer commented 4 years ago

I'm seeing this also with iOS 13

https://github.com/cozmo/jsQR/blob/master/src/locator/index.ts#L451

zspitzer commented 4 years ago

as this seems to be a regression in Safari with iOS 13, I have filed a bug https://bugs.webkit.org/show_bug.cgi?id=211619

Zitus commented 4 years ago

I have iOS 13.4.1 and it seems to work fine, excepting when phone tries to save battery and start screen saving mode.

El vie., 8 may. 2020 12:06, Zac Spitzer notifications@github.com escribió:

as this seems to be a regression in Safari with iOS 13, I have filed a bug https://bugs.webkit.org/show_bug.cgi?id=211619

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/cozmo/jsQR/issues/157#issuecomment-625742837, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEBJTGFQM3LEMFQOBNHGW4LRQPKTRANCNFSM4LG5SNVA .

Zitus commented 4 years ago

I correct. On iPhone jsqr stops reading codes if none is found past the 1 minute mark.

samkuehn commented 4 years ago

I am having the same issue. Has anyone else found a workaround?

gaaamii commented 4 years ago

I am having the same issue on Mac OS X 10.15.4 and Safari 13.1.

Alexnortung commented 3 years ago

I solved this issue by putting a try-catch around the jsQr() call. However there must be some other way to check if the data can be used by jsQr. But what would the solution be. that jsQr should just do nothing instead of throwing the error?

basz commented 3 years ago

I do the same and works

onError = e => {
        const errorMessage = !e ? 'Unknown Error' : e.message || e;
        if (errorMessage === 'RangeError: Array size is not a small enough positive integer.') {
          return;
        }

        worker.removeEventListener('message', onMessage);
        worker.removeEventListener('error', onError);
        clearTimeout(timeout);

        reject('Scanner error: ' + errorMessage);
      };
sigtot commented 3 years ago

We had two issues going on simultaneously on iOS 13, one that caused the camera stream to freeze and one that caused this RangeError. 1) The first one was due to us having our html video element the camera stream hooked up set to hidden like this:

<video ref={ourRef} hidden/>

We think because the video was not visible to the user, safari decided to cut the video stream from the camera, hence freezing the stream. Having the video element visible on screen fixed this.

2) After fixing the freeze issue, the RangeError kept popping up every now and then, but never caused a freeze. We easily circumvented it with a try-catch for now. Just skipping over any frames that resulted in the error.

Hope this can be of help to some of you!

jt-nti commented 3 years ago

I've been trying to work round this issue but no luck so far. (Unfortunately I don't have a device to test it on, and I have no clue what I'm doing!) I've tried @basz's suggestion but that doesn't seem to have worked https://github.com/jt-nti/qr-scanner/blob/71-webkit-bug/src/qr-scanner.js#L220 Any other tips/ideas would be much appreciated, thanks.

Eschon commented 3 years ago

I also ran into this problem recently here is what I've found so far:

I hope this helps someone more familiar with the code of this library to get to the bottom of this since I don't have the resources to dig into it right now.

lisknonanika commented 3 years ago

If you just want to prevent it from freezing, you can modify it as follows. (It is not a fundamental solution.) https://github.com/cozmo/jsQR/blob/master/src/index.ts#L26

function scan(matrix: BitMatrix): QRCode | null {
  try {                                                      // add
    const locations = locate(matrix);
    if (!locations) {
      return null;
    }

    for (const location of locations) {
      .........................................
    }
    return null;
  } catch(e) {                                               // add
    if (e instanceof RangeError) return null;                // add
    throw e;                                                 // add
  }                                                          // add
}