html5-qrcode icon indicating copy to clipboard operation
html5-qrcode copied to clipboard

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

Open mebjas opened this issue 3 years ago • 20 comments

rememberLastUsedCamera permission doesnt seem to work on Safari.

  • Works on Chrome.

Desktop (please complete the following information):

  • OS: Mac OS Big Sur 11.6
  • Browser: Safari
  • Version: 15.0

mebjas avatar Oct 26 '21 16:10 mebjas

Hi @mebjas

I will check this issue.

Regards,

denguyen-tvit avatar Nov 21 '21 13:11 denguyen-tvit

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.

xperseguers avatar Dec 13 '21 13:12 xperseguers

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

mebjas avatar Dec 13 '21 13:12 mebjas

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.

xperseguers avatar Dec 13 '21 13:12 xperseguers

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

denguyen-tvit avatar Dec 14 '21 03:12 denguyen-tvit

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.

rlueder avatar Aug 09 '22 18:08 rlueder

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.

NickVst avatar Dec 08 '22 14:12 NickVst

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: @.***>

mebjas avatar Dec 08 '22 15:12 mebjas

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

idanwe avatar Mar 29 '23 09:03 idanwe

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

waiting for the issue to be solved

thasnigogo avatar Apr 26 '23 08:04 thasnigogo

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

ROBERT-MCDOWELL avatar Apr 26 '23 11:04 ROBERT-MCDOWELL

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

`

jhosuapp avatar Sep 01 '23 15:09 jhosuapp

Does ios17 enable this to work on iOS devices yet?

caseydierking avatar Sep 29 '23 15:09 caseydierking

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

cyril23 avatar Oct 16 '23 11:10 cyril23

@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 avatar Oct 17 '23 13:10 caseydierking

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

caseydierking avatar Jan 23 '24 15:01 caseydierking

still experiencing this issue

JuneRodney avatar Mar 01 '24 08:03 JuneRodney

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

  • Remove my website from the home screen
  • Went to my website using Safari
  • 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
  • Added a bookmark of my website to my home screen so that it becomes an "app" (lightweight PWA actually)
  • 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.

ROBERT-MCDOWELL avatar Mar 01 '24 12:03 ROBERT-MCDOWELL

@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?

ROBERT-MCDOWELL avatar Mar 01 '24 12:03 ROBERT-MCDOWELL