Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS 15] Add support for new delegate WKUIDelegate decideMediaCapturePermissionFor #1671

Closed
nanosonde opened this issue Jun 18, 2021 · 6 comments · Fixed by #1850
Closed

Comments

@nanosonde
Copy link

nanosonde commented Jun 18, 2021

Feature request / problem description
Every call to getUserMedia() from within a WKWebView instance will lead to a new permission popup requiring the user to allow/deny access to the camera and/or microphone. This is quite annoying from a user perspective.

Example use-case: I use an audio/video capable Home Assistant card to have an audio/video connection to my doorbell within HA lovelace UI.

Describe the solution you'd like
Implement the new delegate WKUIDelegate decideMediaCapturePermissionFor to handle getUserMedia() media capture permission requests so that the user does not get a permission prompt for camera/microphone with every call to getUserMedia() when loading or reloading a webpage from within an existing instance of WKWebView.

Additional context

  1. Original bug report for iOS 14.3: https://bugs.webkit.org/show_bug.cgi?id=220416
  2. Another related forum topic: https://developer.apple.com/forums/thread/669011
  3. Presentation of the new delegate on WWDC 2021 at timestamp 14:40: https://developer.apple.com/videos/play/wwdc2021/10032/
  4. A clarification about the new delegate in the Apple forum: https://developer.apple.com/forums/thread/682293
  5. getUserMedia(): https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia
  6. Somehow related issue: Add microphone access (NSMicrophoneUsageDescription) #1319
@zacwest
Copy link
Member

zacwest commented Jun 20, 2021

Looks like this is declared as being supported back to iOS 14.5, but requires Xcode 13 to use it.

@zacwest
Copy link
Member

zacwest commented Jun 20, 2021

These delegate methods are all over the place - some are async and some pass in a block for a decision handler. Probably best to wait until later in the Xcode 13 beta period before playing with it.

@idoodler
Copy link

I tried to implement it. Now the prompts are gone, but I don't get the orange recording indicator of iOS and I don't hear anything:/

@nanosonde
Copy link
Author

I tried to implement it. Now the prompts are gone, but I don't get the orange recording indicator of iOS and I don't hear anything:/

What exactly have you tested where you do not hear anything?

@zacwest
Copy link
Member

zacwest commented Sep 21, 2021

It looks like the only API they added for this in the iOS 15 release is:

- (void)webView:(WKWebView *)webView
requestMediaCapturePermissionForOrigin:(WKSecurityOrigin *)origin
initiatedByFrame:(WKFrameInfo *)frame
type:(WKMediaCaptureType)type
decisionHandler:(void (^)(WKPermissionDecision decision))decisionHandler;

which is documented (only in the headers, not in the actual docs, sigh) as:

If not implemented, the result is the same as calling the decisionHandler with WKPermissionDecisionPrompt.

This may behave as you'd like without any app-level changes.

@zacwest
Copy link
Member

zacwest commented Sep 21, 2021

Oh I see, you'd like the app to always say yes so it doesn't always prompt. That also seems doable, assuming it is prompting correctly.

zacwest added a commit that referenced this issue Sep 21, 2021
Fixes #1671.

## Summary
Always allows access to to the camera and microphone via `navigator.mediaDevices.getUserMedia`.

## Any other notes
Since this is gated on the app-level system permission for Camera and Microphone, it feels silly to require the user to allow access to them during the normal app runtime - this is exclusively a weird WebView behavior-ism. Also doesn't feel worth making this a preference - if users don't want the frontend to access it, it seems to me like the app-level permission is enough.

Tested this by using e.g. [the WebRTC samples](https://webrtc.github.io/samples/): going to a video or audio or both test page, after granting app permission, successfully starts right away.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants