qr-scanner icon indicating copy to clipboard operation
qr-scanner copied to clipboard

[question] How to detect blocked permission

Open Svatex opened this issue 2 years ago • 2 comments

Hi guys, first of all thanks for your good work! Best Qr scanner, easy to set up and works well.

But back to my question. Is there any easy way how to detect, that the user decides not to give permission for the camera across all browsers? Would be awesome if scanner.start() would return something like {permissionGranted: true/false}. Just an idea, I have no clue how this whole thing works internally and if it's even possible.

I did found workaround with QrScanner.listCameras(true). If I call listCameras after scanner.start() and at least one label in listedCameras is"Default Camera" it usually means that the user didn't give access to cameras. But it's a very sketchy solution, I have no idea if any manufacturer doesn't call their cameras this way. And also it doesn't work for Safari... Iam not able to invoke camera and I get just white screen :/

Svatex avatar Mar 23 '22 10:03 Svatex

You can simply catch the error :)

const qrScanner = new QrScanner(/*...*/);
qrScanner.start().catch((e) => {
  // handle error
});

ph1p avatar Aug 06 '22 19:08 ph1p

@ph1p is there a way to turn on this prompt to ask the user to allow camera access?

avxkim avatar Jan 18 '23 19:01 avxkim