jsQR icon indicating copy to clipboard operation
jsQR copied to clipboard

iOS Safari freezes

Open lucakermas opened this issue 6 years ago • 13 comments

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.

lucakermas avatar Mar 13 '20 08:03 lucakermas

Was this error corrected?

Zitus avatar May 02 '20 09:05 Zitus

I'm seeing this also with iOS 13

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

zspitzer avatar May 08 '20 07:05 zspitzer

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

zspitzer avatar May 08 '20 10:05 zspitzer

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 [email protected] 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 avatar May 08 '20 10:05 Zitus

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

Zitus avatar May 17 '20 10:05 Zitus

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

samkuehn avatar May 29 '20 18:05 samkuehn

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

gaaamii avatar Jun 04 '20 02:06 gaaamii

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?

Alexnortung avatar Aug 20 '20 10:08 Alexnortung

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);
      };

basz avatar Aug 20 '20 13:08 basz

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.

  1. 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!

sigtot avatar Aug 31 '20 11:08 sigtot

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.

jt-nti avatar Oct 01 '20 08:10 jt-nti

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

  • The problem happens with Safari on iOS 14.1 (and probably 13, haven't been able to test that) on an older phone with iOS 12 there appear to be no problems.
  • The error doesn't happen when the phone is plugged in or connected to my Mac (which makes this mess even more cumbersome to debug).
  • It also seems to be connected to the data size of the scanned code. 21x21 or 25x25 modules works fine while bigger codes cause the error after about 30 seconds of scanning.
  • According to the error message it seems to be a problem with typed arrays. Although I can't really tell where exactly in the code it comes from a first random guess would be here: https://github.com/cozmo/jsQR/blob/8851ab5cc5fecd646be668ccd34612ccc236d9c3/src/decoder/decoder.ts#L307

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.

Eschon avatar Nov 13 '20 10:11 Eschon

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
}

lisknonanika avatar Dec 24 '20 01:12 lisknonanika