Bug 215884 - getUserMedia recurring permissions prompts in standalone when hash changes
Summary: getUserMedia recurring permissions prompts in standalone when hash changes
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebRTC (show other bugs)
Version: Safari 13
Hardware: iPhone / iPad iOS 13
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
: 212040 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-08-27 02:41 PDT by nfckngspmpls
Modified: 2021-02-14 01:39 PST (History)
11 users (show)

See Also:


Attachments
Per site setting iOS UI (1.01 MB, image/jpeg)
2020-12-16 05:32 PST, youenn fablet
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description nfckngspmpls 2020-08-27 02:41:40 PDT
Context:
I have a web app with a hash router. Once I am done analysing the camera stream and showing results my router changes the hash to a result route. When I come back to the camera view, I am prompted for the camera permissions again, even though I never left the web app. This behaviour does not happen in Safari for iOS.


Current behaviour:
In standalone mode, iOS is revoking the camera permissions every time the hash changes.

Expected behaviour:
In browser mode, once I am granted the camera use by the user, I can change the hash without loosing the camera permissions.

Steps to reproduce:
1) Add a video tag to page
2) Ask for camera permissions and attach the stream to the video tag
3) Add a <a href="#"> to page
4) click on link

In standalone mode: video stream is gone.
In browser mode: video stream is still there.

Current workaround:
Set the Vue router to abstract mode.
Comment 1 Radar WebKit Bug Importer 2020-08-29 11:39:39 PDT
<rdar://problem/68001080>
Comment 2 youenn fablet 2020-09-16 01:30:27 PDT
Thanks, I was able to repro with airhorner.
It seems as if there is a navigation which stops all the capture tracks and reset the permissions when doing hash navigations in Web.app but not iOS Safari.
Comment 3 Alex Suzuki 2020-10-19 07:24:20 PDT
I have multiple PWAs which scan barcodes using and show the camera preview with getUserMedia. They use Angular routing.

Everything works fine in Safari, but when added to home screen (PWA), the camera permission prompt will appear every time the route changes.

Currently the only workaround we can offer to users is to provide blanket camera permissions (all web sites) in Safari.

This is probably related to this issue.
Comment 4 Michal 2020-12-16 05:14:36 PST
(In reply to Alex Suzuki from comment #3)
> 
> Everything works fine in Safari, but when added to home screen (PWA), the
> camera permission prompt will appear every time the route changes.
> 
> This is probably related to this issue.


We have exactly this problem with our PWA which is based on QR scanner. It would be nice to have this working as in Safari.
Comment 5 Michal 2020-12-16 05:20:33 PST
(In reply to Alex Suzuki from comment #3)
> I have multiple PWAs which scan barcodes using and show the camera preview
> with getUserMedia. They use Angular routing.
> 
> Currently the only workaround we can offer to users is to provide blanket
> camera permissions (all web sites) in Safari.
> 

Whad did you mean by this? Can you explain this workaround more please?
Comment 6 youenn fablet 2020-12-16 05:32:22 PST
(In reply to Michal from comment #5)
> (In reply to Alex Suzuki from comment #3)
> > I have multiple PWAs which scan barcodes using and show the camera preview
> > with getUserMedia. They use Angular routing.
> > 
> > Currently the only workaround we can offer to users is to provide blanket
> > camera permissions (all web sites) in Safari.
> > 
> 
> Whad did you mean by this? Can you explain this workaround more please?

In iOS Safari, users can persistently grant camera/microphone access from Safari UI.
Comment 7 youenn fablet 2020-12-16 05:32:50 PST
Created attachment 416332 [details]
Per site setting iOS UI
Comment 8 youenn fablet 2020-12-16 05:33:35 PST
I uploaded a screenshot that shows where to get per-site settings UI
Comment 9 Michal 2020-12-16 06:47:31 PST
(In reply to youenn fablet from comment #8)
> I uploaded a screenshot that shows where to get per-site settings UI

Yes I see, thank you for explanation of this. Of course this is working but there is need to do it manually by users. Which I don't want to delegate this problem to end-users. If you are calculating with thousands of them.

Our problem is mainly with "Installed" PWA - "Add to Home screen" (in Safari), where this permission is not persisted after you did this install of the app.
Comment 10 youenn fablet 2020-12-16 07:06:33 PST
As a temporary workaround, I wonder whether the following would work:
- Start capture
- Before navigating inside the page, stop the capture by calling stream.getTracks().forEach(t => t.stop())
- Navigate within the same page
- Restart capture (hopefully without a prompt this time).
Comment 11 youenn fablet 2021-01-05 04:49:39 PST
*** Bug 212040 has been marked as a duplicate of this bug. ***
Comment 12 youenn fablet 2021-01-05 04:52:48 PST
The fix is not in WebKit but in Safari standalone mode implementation.
I'll keep this bug open until validation is done this works as expected.
Comment 13 Mauricio W 2021-01-11 21:04:29 PST
I don't think this issue is with Safari implementation.
It also happens when running an app with WKWebView. Any changes to the path of the URL causes calls to `getUserMedia` to request permissions from the user again.
Comment 14 Mauricio W 2021-01-11 21:52:13 PST
It looks like the problem is a bit more serious in WKWebView. 

After allowing the prompt, any subsequent calls to `getUserMedia` after some period of time (looks to be about 90 seconds) will also trigger the prompt for permissions.

This happens even without navigating away from the page, regardless of if the user was active or inactive in that time.
Comment 15 youenn fablet 2021-01-12 01:32:17 PST
(In reply to Mauricio W from comment #14)
> It looks like the problem is a bit more serious in WKWebView. 
> 
> After allowing the prompt, any subsequent calls to `getUserMedia` after some
> period of time (looks to be about 90 seconds) will also trigger the prompt
> for permissions.
> 
> This happens even without navigating away from the page, regardless of if
> the user was active or inactive in that time.

This is a different bug, which might best be fixed by exposing a delegate to control getUserMedia prompt.
If capture is ongoing, prompt should not happen again until 24 hours.
If capture is not ongoing, prompt should happen again after 1 minute of inactivity.
This is the same behavior as Safari.
Comment 16 Mauricio W 2021-01-12 05:50:50 PST
Thanks for the reply, youenn. The documentation for this is rather scarce, so I wasn't sure. Thank you for clearing that up.

I don't mean to sidetrack this thread, but since you brought it up: could you explain a bit more on how I could use a delegate to handle this? Reading through the WKWebview documentation there doesn't seem to be an obvious answer to me. I also spent some time trying to understand how the UserMediaRequest gets sent out, but I couldn't really understand the flow.
Comment 17 youenn fablet 2021-01-12 05:55:38 PST
(In reply to Mauricio W from comment #16)
> Thanks for the reply, youenn. The documentation for this is rather scarce,
> so I wasn't sure. Thank you for clearing that up.
> 
> I don't mean to sidetrack this thread, but since you brought it up: could
> you explain a bit more on how I could use a delegate to handle this? Reading
> through the WKWebview documentation there doesn't seem to be an obvious
> answer to me. I also spent some time trying to understand how the
> UserMediaRequest gets sent out, but I couldn't really understand the flow.

UserMediaRequest is sent through IPC to UIProcess.
It is processed in UserMediaPermissionRequestManagerProxy which ultimately may call a WKWebView delegate dedicated to getUserMedia permission.
This delegate is not yet exposed though.
Comment 18 Dan Strengier 2021-01-26 10:42:05 PST
I too have PWAs that use the camera to scan barcodes.  It's proving very cumbersome for our users to confirm camera access every time they try and scan a QR code.

The workaround to always allow camera access across all Safari websites is a *really bad workaround* because it completely breaks user's privacy controls, just so they can seamlessly scan barcodes using our app.
Comment 19 Bryce Wilson 2021-02-11 01:49:48 PST
I can also confirm this issue via a PWA install on home screen, the camera is requested on every page there is a camera instance initiated.
Comment 20 youenn fablet 2021-02-14 01:39:19 PST
Please check this in latest iOS 14.5 beta.