mebjas / html5-qrcode

A cross platform HTML5 QR code reader. See end to end implementation at: https://scanapp.org
https://qrcode.minhazav.dev
Apache License 2.0
5.09k stars 978 forks source link

[Safari] The library doesn't seem to remember the camera permission #332

Open mebjas opened 3 years ago

mebjas commented 3 years ago

rememberLastUsedCamera permission doesnt seem to work on Safari.

Desktop (please complete the following information):

denguyen-tvit commented 3 years ago

Hi @mebjas

I will check this issue.

Regards,

xperseguers commented 2 years ago

Same problem with Safari (or Chrome) on an iPhone with iOS 15 (currently on 15.2 for me). This remembers as intended on an Android device but not on an iPhone.

mebjas commented 2 years ago

Observed the same. @denguyen-tvit are you actively working on a PR.

xperseguers commented 2 years ago

Edit: found a way to make it work:

  1. Remove my website from the home screen
  2. Went to my website using Safari
  3. Allowed the website to always have access to camera according to this post: https://stackoverflow.com/questions/48847388/how-to-permanently-allow-usage-of-camera-on-trusted-websites-with-ios-safari/57368061#57368061
  4. Added a bookmark of my website to my home screen so that it becomes an "app" (lightweight PWA actually)
  5. Had to grant once access from within that bookmark but now every time I try to launch the QR reader, it looks like access is granted without further ask.
denguyen-tvit commented 2 years ago

@mebjas I checked around and currently don't have idea to remember camera permission on iPhone

rlueder commented 2 years ago

This seems to be related to underlying issues with WebKit with bugs reported here: https://bugs.webkit.org/show_bug.cgi?id=220416 https://bugs.webkit.org/show_bug.cgi?id=215884

This demo from wwdc2021 is relevant and specifically mentions getUserMedia starting at 12:35 https://developer.apple.com/videos/play/wwdc2021/10032/

And documentation on the new APIs: https://developer.apple.com/documentation/webkit/wkpermissiondecision/

We also have a new API to allow you to decide when and how to prompt the user for camera and microphone permissions when working with web content. Once you have obtained user permissions for the camera and microphone via normal entitlements and prompts, you can decide if the permission prompts should be shown. You can use this to implement your own prompt or remember the users' previous response for web content you control and trust.

NickVst commented 1 year ago

I just ran into this issue myself. I was wondering if there's any progress with remembering permissions on iOS; asking our users to give camera permissions every time the app is restarted is not very desirable.

mebjas commented 1 year ago

It's not supported on iOS. It's a platform limitation will share more details on this thread soon.

On Thu, Dec 8, 2022, 22:36 Nick Versteeg @.***> wrote:

I just ran into this issue myself. I was wondering if there's any progress with remembering permissions on iOS; asking our users to give camera permissions every time the app is restarted is not very desirable.

— Reply to this email directly, view it on GitHub https://github.com/mebjas/html5-qrcode/issues/332#issuecomment-1342831824, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAW6HBMN2Y7YBTFROAIPVHLWMHW5HANCNFSM5GYGNFUA . You are receiving this because you were assigned.Message ID: @.***>

idanwe commented 1 year ago

Does someone has any updates on this matter on iOS? I'm experiencing the same issue

thasnigogo commented 1 year ago

Does someone has any updates on this matter on iOS? I'm experiencing the same issue

waiting for the issue to be solved

ROBERT-MCDOWELL commented 1 year ago

your issue comes from Mac OS and its permissions. check how you set them trough MacOS settings

jhosuapp commented 1 year ago

If you add "Html5Qrcode.getCameras()" it will ask for permissions every time it tries to scan

`

    const html5QrCode = new Html5Qrcode("reader");
    const qrCodeSuccessCallback = (decodedText, decodedResult) => {
        /* handle success */
        console.log(`Scan result: ${decodedText}`);
        //STOP SCANNER
        html5QrCode.stop();
    }
    //CONFING
    const config = { fps: 10, qrbox: 220 };
    //START SCAN
    Html5Qrcode.getCameras().then(devices => {
        html5QrCode.start({ facingMode: { exact: "user"} }, config, qrCodeSuccessCallback)
        .then(res=>{
            alert('init camera');
        }).catch((err)=>{
            alert('error permissions');
        });
    }).catch((err)=>{
        alert('error permissions');
    });

`

caseydierking commented 1 year ago

Does ios17 enable this to work on iOS devices yet?

cyril23 commented 1 year ago

If you add "Html5Qrcode.getCameras()" it will ask for permissions every time it tries to scan

does this mean I can do it as follows in order to avoid 2+ camera permission requests?

  1. first scan: call getCameras -> this results in a camera permission request -> OK and save the camera ID of this device in my database
  2. 2nd+ scan: use the saved camera ID during html5QrCode.start
caseydierking commented 1 year ago

@cyril23 Did you manage to get this working like this? I'm wondering if anyone has any time of workaround for now for iOS.

caseydierking commented 10 months ago

I am wondering if anyone is still having this issue? I still am.

JuneRodney commented 8 months ago

still experiencing this issue

ROBERT-MCDOWELL commented 8 months ago

it's a IOS limitation, you have to allow your cam everytime when you close and start a browser, unless if you do what it said above like

ROBERT-MCDOWELL commented 8 months ago

@mebjas if users experience problems with some devices maybe the best would be to ask a contribution to buy this device and work on it. what do you think?

WestrandSublimation commented 6 months ago

The camera permission is saved on all devices, even iOS. Safari does not ask for it again when granted, however, the webview in my app still ask for permission although the camera access is granted in the app settings in the system. Any solutions?