apache / cordova-ios

Apache Cordova iOS
https://cordova.apache.org/
Apache License 2.0
2.16k stars 989 forks source link

[enhancement] add requestMediaCapturePermissionForOrigin support to avoid multiple permission request on getUserMedia call #1166

Open RSATom opened 2 years ago

RSATom commented 2 years ago

Feature Request

Motivation Behind Feature

If use native WebRTC from WKWebView inside Cordova, every getUserMedia leads to new permission request to user. And this makes native WebRTC almost not suitable for use in production.

Feature Description

The simplest solution is add

- (void)webView:(WKWebView *)webView
  requestMediaCapturePermissionForOrigin:(WKSecurityOrigin *)origin
  initiatedByFrame:(WKFrameInfo *)frame
  type:(WKMediaCaptureType)type
  decisionHandler:(void (^)(WKPermissionDecision decision))decisionHandler
  API_AVAILABLE(ios(15.0))
{
  decisionHandler(WKPermissionDecisionGrant);
}

to https://github.com/apache/cordova-ios/blob/master/CordovaLib/Classes/Private/Plugins/CDVWebViewEngine/CDVWebViewUIDelegate.m but it's definitely insecure solution, and application should have ability to respond to this request, or provide list of safe origins.

Alternatives or Workarounds

Didn't find any

fq-selbach commented 2 years ago

Same issue here with microphone access permission in general (aka everything related to navigator.mediaDevices).

Any news?

react-native-webview solution: https://github.com/react-native-webview/react-native-webview/pull/2257

Ionic WKWebView solution: https://github.com/ionic-team/capacitor/issues/5485 https://github.com/ionic-team/capacitor/blob/main/ios/Capacitor/Capacitor/WebViewDelegationHandler.swift#L53

Home Assistant solution: https://github.com/home-assistant/iOS/issues/1671

fquirin commented 2 years ago

I've tried the suggested solution and it's working pretty well. The app will still ask you once if you've never given the permission before, it will remember it afterwards and other instances of WKWebView with inAppBrowser for example will not automatically get the same permission!

derMani commented 2 years ago

I've tried the suggested solution and it's working pretty well. The app will still ask you once if you've never given the permission before, it will remember it afterwards and other instances of WKWebView with inAppBrowser for example will not automatically get the same permission!

This works really good! I It would be nice to have this implemented by default or as an option. For the moment, we wrote a hook for it to modify the file.