question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Undefined error in prepareCaptureCanvas method, if scanner is closed within scanDelay time after scanning a QR code successfully

See original GitHub issue

Bug, feature request, or proposal:

What am I trying to do: I open an overlay to scan the QR code and when it was scanned successfully, I want to immediately close it. If I do that through the scanSuccess callback, it will throw an error that “this.imageElement.naturalWidth” is undefined

What is the expected behavior?

After a successful scan, I want to be able to immediately stop scanning and/or hide the entire scanner without any errors being thrown.

What is the current behavior?

After a successful scan, if I stop scanning immediately, it will throw an error “Cannot read property ‘naturalWidth’ of undefined” in the prepareCaptureCanvas method on the imageElement. This is because of

What are the steps to reproduce?

Here you can test both scenarios, once with the delay and once without, to see that the same code works as long as I wait after scanning and it does not, once I immediately stop scanning. https://zxing-ngx-scanner-n5hoke.stackblitz.io/

Which versions of Angular, ngx-scanner, OS, TypeScript, browsers are affected?

Tested with Angular 4 and Angular 5, ngx-scanner 1.0.5 OS, TS version and browser are no factor.

Is there anything else we should know?

A suggestion on how to “fix” it, is to let it silently fail in the beginning of the decode method, if neither videoElement nor imageElement are found, e.g.: if (undefined === this.videoElement && undefined === this.imageElement) return;

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
xtj7commented, Apr 17, 2018

Thanks a lot guys! And also: great work on the ngx-scanner 😃

2reactions
werthdavidcommented, Apr 16, 2018

Sorry guys, little time atm… I don’t exactly remember what I thought when I initially implemented the timeout but if I remember correctly my intention was to prevent the scanner to pass a result to the output multiple times after an successful scan e.g. the user points the camera to the code for 1s and the result is outputted 3 times (that was the case with my Android App that uses ZXing Java).

Read more comments on GitHub >

github_iconTop Results From Across the Web

9 reasons Why Your QR Code is Not Working - Beaconstac blog
Even the most advanced QR Code scanners cannot scan QR Codes if not created correctly. Or was it the faulty QR Code generator?...
Read more >
12 Reasons why your QR code is not working
QR codes are not working for a variety of reasons. These codes are developed to be scanned by smartphone gadgets.
Read more >
Unable to Scan QR Code? Here's How to Fix a QR Code.
If a QR code won't scan or doesn't work, we got you. Here's a rundown of common QR code issues that leave folks...
Read more >
Unable to scan QR Code via Camera - Apple Developer
Unable to scan QR Code via Camera App on MDM-managed iOS 14 devices ... After un-enrolling the device with MDM, the QR Code...
Read more >
BarCodeScanner - Expo Documentation
BarCodeScanner. expo-barcode-scanner provides a React component that renders a viewfinder for the device's camera (either front or back) and will scan bar ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found