Bug 208667 - getUserMedia does not work in WKWebView-based browsers like Chrome, Firefox.
Summary: getUserMedia does not work in WKWebView-based browsers like Chrome, Firefox.
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified iOS 13
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-05 15:10 PST by Erik Hodge
Modified: 2020-10-09 06:21 PDT (History)
46 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Hodge 2020-03-05 15:10:20 PST
getUserMedia does not work in iOS WKWebView-based browsers like Chrome, Firefox, works in iOS Safari.

Bug 185448 has been resolved, but it only addresses apps launched from the iOS home screen:
https://bugs.webkit.org/show_bug.cgi?id=185448
A comment in 185448 says it is confirmed fixed in iOS 13.4 beta 1, and that getUserMedia still doesn't work in Chrome in that build
Comment 1 gabrielstuff 2020-03-05 15:18:03 PST
Hello,

I confirm that this is utterly needed. WKWebView-based browsers like Chrome, Firefox, Brave, Phonegap App, Capacitor, etc... is a must !
Comment 2 Peter 2020-03-05 15:25:22 PST
Agreed this opens up whole new possibilities.
Comment 3 jamauro 2020-03-05 15:35:49 PST
Please fix! 

I was super excited when I thought it was already addressed with https://bugs.webkit.org/show_bug.cgi?id=185448 and then equally as bummed when I realized that would not address WKWebView-based browsers. Truly a rollercoaster of emotions.

Thanks for listening.
Comment 4 Alejandro Silva 2020-03-05 23:39:03 PST
I thought iOS beta 13.4 fixed WKWebView to have getUserMedia, it would be cool to have it to avoid the use of SFSafariViewController inside an app, just to start a WebRTC flow
Comment 5 Matt T 2020-03-08 12:47:18 PDT
I can unfortunately verify in 13.4 beta 4 that navigator.getUserMedia is still not there for WKWebView :( Apple please, this blocks so many apps!
Comment 6 KeiroMidori 2020-03-17 12:57:41 PDT
It indeed is very much needed! Please Apple make it happen.
Comment 7 Peter 2020-03-18 12:37:36 PDT
Is it reasonable to expect this will be fixed, since Bug 185448 was finally resolved, and this is closely related?
Comment 8 Eric 2020-04-04 00:18:50 PDT
Hi.

Just want to report that due to THIS single bug, my company advises all our clients to buy Samsung tablets instead of iPads.

This bug accounts for probably hundreds of Android tablet purchases for this month.

If you want to stay relevant in the browser market during these days of stay-at-home, this is a MUST FIX.
Comment 9 Simon 2020-04-08 14:14:18 PDT
Please fix this one. 

It is super annoying that I cannot use getusermedia in WKwebview Apps. Please allow to use this function!
Comment 10 b34r 2020-04-12 01:11:15 PDT
Looking forward to this fix :)
Comment 11 Simon 2020-04-13 05:46:25 PDT
(In reply to Eric from comment #8)
> Hi.
> 
> Just want to report that due to THIS single bug, my company advises all our
> clients to buy Samsung tablets instead of iPads.
> 
> This bug accounts for probably hundreds of Android tablet purchases for this
> month.
> 
> If you want to stay relevant in the browser market during these days of
> stay-at-home, this is a MUST FIX.


We changed to SFSarafiWebView to fix this. You cant customize this view, but at least it works.
Comment 12 Eric 2020-04-13 12:39:50 PDT
(In reply to Simon from comment #11)
> (In reply to Eric from comment #8)
> > Hi.
> > 
> > Just want to report that due to THIS single bug, my company advises all our
> > clients to buy Samsung tablets instead of iPads.
> > 
> > This bug accounts for probably hundreds of Android tablet purchases for this
> > month.
> > 
> > If you want to stay relevant in the browser market during these days of
> > stay-at-home, this is a MUST FIX.
> 
> 
> We changed to SFSarafiWebView to fix this. You cant customize this view, but
> at least it works.

Thank you Simon for your reply.

We use the Cordova framework for our app and SFSafariWebView cannot fit 
in what we do.

Until Apple fixes WkWebViews, we have no other choices than recommend Android.
Comment 13 luizfilipe2557 2020-04-16 10:52:23 PDT
Please Apple, give the deserved attention your software needs. We just wanna make awesome software for your once excellent platform.
Comment 14 Frederik Riedel 2020-04-17 06:36:18 PDT
It would be great to have the getUserMedia capabilities in WKWebView. Not only for 3rd party web browsers, as mentioned above, but also for 3rd party apps, embedding Web View content that utilizes WebRTC.
Comment 15 Peter 2020-04-17 07:00:19 PDT
Yes, much more so than support in Chrome
or Firefox is the need for this in our apps.
Comment 16 Peter 2020-05-07 06:19:29 PDT
In the last two weeks alone I’ve turned down four potential huge deals for integrations of my web app in other people’s mobile apps... For no other reason than this bug.

Please, please get on this.
Comment 17 Mickael 2020-05-15 07:41:20 PDT
I have a WKWebView in my macOS app and I am trying to enable the userMedia. To do this I have to use private API.

I have successfully enabled userMedia in the webview by creating a category in Objective-C:

```
@interface WKPreferences (MyPreferences)
- (void)_setMediaDevicesEnabled:(BOOL)enabled;
- (void)_setMediaStreamEnabled:(BOOL)enabled;
- (void)_setWebRTCLegacyAPIEnabled:(BOOL)enabled;
- (void)_setAVFoundationEnabled:(BOOL)enabled;
- (void)_setMediaSourceEnabled:(BOOL)enabled;

- (void)setMediaDevicesEnabled:(BOOL)enabled;
@end
```
And:
```
@implementation WKPreferences (MyPreferences)

- (void)setMediaDevicesEnabled:(BOOL)enabled {
    [self _setAVFoundationEnabled:enabled];
    [self _setMediaStreamEnabled:enabled];
    [self _setMediaSourceEnabled:enabled];
    [self _setWebRTCLegacyAPIEnabled:enabled];
    [self _setMediaDevicesEnabled:enabled];
}

@end
```
Using in Swift code:

```
webView.configuration.preferences.setMediaDevicesEnabled(true)
```

This code makes webviews appear their icons to record the voice or launch video. In reality just it was enough to enable `(void) _setMediaDevicesEnabled: (BOOL)enabled` but since it does not work entirely so I have to add all the others.

The problem is that when I click in the webview on the record button or start the video, I get this error:

```
[plugin] AddInstanceForFactory: No factory registered for id <CFUUID 0x6000003b14c0> F8BB1C28-BAE8-11D1-9C31-00032314CD45 HALC_ShellDriverPlugIn::Open: Can't get a pointer to the Open routine [] CMIO_DAL_PlugInManagement.cpp:191:Initialize Missing device-camera entitlement
```

I guess I need to implement delegates to be able to request permission and launch the camera or microphone. I found delegates who could be the right ones in the `WKUIDelegatePrivate`

```

- (void)_webView:(WKWebView *)webView requestUserMediaAuthorizationForDevices:(_WKCaptureDevices)devices url:(NSURL *)url mainFrameURL:(NSURL *)mainFrameURL decisionHandler:(void (^)(BOOL authorized))decisionHandler;
- (void)_webView:(WKWebView *)webView checkUserMediaPermissionForURL:(NSURL *)url mainFrameURL:(NSURL *)mainFrameURL frameIdentifier:(NSUInteger)frameIdentifier decisionHandler:(void (^)(NSString *salt, BOOL authorized))decisionHandler;
- (void)_webView:(WKWebView *)webView mediaCaptureStateDidChange:(_WKMediaCaptureState)state;
- (void)_webView:(WKWebView *)arg1 requestMediaCaptureAuthorization:(unsigned long long)arg2 decisionHandler:(void (^)(BOOL))arg3;
```

So I tried to implement them but the delegates are NEVER CALLED. This is my problem: how can I initialize WKUIDelegatePrivate?

The code I tried:

```
@protocol WKUIDelegatePrivate <WKUIDelegate>

- (void)_webView:(WKWebView *)webView requestUserMediaAuthorizationForDevices:(_WKCaptureDevices)devices url:(NSURL *)url mainFrameURL:(NSURL *)mainFrameURL decisionHandler:(void (^)(BOOL authorized))decisionHandler;
- (void)_webView:(WKWebView *)webView checkUserMediaPermissionForURL:(NSURL *)url mainFrameURL:(NSURL *)mainFrameURL frameIdentifier:(NSUInteger)frameIdentifier decisionHandler:(void (^)(NSString *salt, BOOL authorized))decisionHandler;
- (void)_webView:(WKWebView *)webView mediaCaptureStateDidChange:(_WKMediaCaptureState)state;
- (void)_webView:(WKWebView *)arg1 requestMediaCaptureAuthorization:(unsigned long long)arg2 decisionHandler:(void (^)(BOOL))arg3;

- (void)registerDelegate:(WKWebView *)webView;
@end


@interface UserMediaProvider : NSObject <WKUIDelegatePrivate>
@end
```

And:
```
@implementation UserMediaProvider

- (id)init {
    self = [super init];
    if (self) {
    }

    return self;
}

- (void)_webView:(WKWebView *)webView requestUserMediaAuthorizationForDevices:(_WKCaptureDevices)devices url:(NSURL *)url mainFrameURL:(NSURL *)mainFrameURL decisionHandler:(void (^)(BOOL authorized))decisionHandler {
    NSLog(@"AAAAAAAAA");
}

- (void)_webView:(WKWebView *)webView checkUserMediaPermissionForURL:(NSURL *)url mainFrameURL:(NSURL *)mainFrameURL frameIdentifier:(NSUInteger)frameIdentifier decisionHandler:(void (^)(NSString *salt, BOOL authorized))decisionHandler {
    NSLog(@"BBBBBB");
}

- (void)_webView:(WKWebView *)webView mediaCaptureStateDidChange:(_WKMediaCaptureState)state {
    NSLog(@"CCCCCC");
}

- (void)_webView:(WKWebView *)arg1 requestMediaCaptureAuthorization:(unsigned long long)arg2 decisionHandler:(void (^)(BOOL))arg3{
    NSLog(@"PPPPPPP");
}


- (void)registerDelegate:(WKWebView *)webView {
    webView.UIDelegate = self;
}

@end
```

Using from Swift code:

```
webview.registerDelegate(self)
```

I see WKWebView.mm for example that uiDelegatePrivate is cast to UIDelegate when used:

```
id<WKUIDelegatePrivate> uiDelegatePrivate = static_cast<id <WKUIDelegatePrivate>>([self UIDelegate]);
```

Also I can see in UIDelegate.mm That the delegate is called via uidelegate
```

{
    auto delegate = m_uiDelegate.m_delegate.get();
    if (!delegate || !m_uiDelegate.m_delegateMethods.webViewRequestUserMediaAuthorizationForDevicesURLMainFrameURLDecisionHandler) {
        request.deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::UserMediaDisabled); // THIS
        return true;
    }

    bool requiresAudio = request.requiresAudio();
    bool requiresVideo = request.requiresVideo();
    if (!requiresAudio && !requiresVideo) {
        request.deny(UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::NoConstraints);
        return true;
    }
...
```

How can I enable these delegate methods to be called?

I specify that it is for internal application of my company so I do not want the upload to the store
Comment 18 geckse 2020-06-02 03:17:57 PDT
This bug currently affects heavily our iOS users of our WKWebkit based app. We've implemented a video-capture-feature the getUserMedia-Way and found a workaround (get camera stream trough the cordova-plugin-iosrtc plugin and render the stream to a canvas and capture this canvas with ffmpeg.) but it significantly impacts the performance and thus experience of our users. I don't know what else to tell them but that iOS simply does not support this feature, at the moment..
Comment 19 Sudheer 2020-06-10 12:46:03 PDT
We do rely on getUserMedia to share camera across all platforms and this is seems to limiting our feature capability on IOS native app with webview. It will be nice to address this as it opens up new possibilities and features.
Comment 20 frik 2020-06-16 11:50:47 PDT
+1
Comment 21 frik 2020-06-16 11:52:36 PDT
This also breaks WebRTC voice.
Comment 22 Matt A 2020-06-26 19:29:00 PDT
I can also confirm that this is still not fixed in iOS 14 Beta 1. I have reported it via Apple Developer Bug reporting tool, so hopefully another angle will help us. This is particularly worrying now since users can chose to used 3rd party apps so opening links via an invite in mail or SMS will get our users stuck.

Apple also does not have support for redirecting the user back to Safari which makes this a total mess. 

PLEASE WebKit team, solve this in iOS 14.
Comment 23 Peter 2020-07-02 10:33:54 PDT
With Apple preparing to allow users to change their default browser in iOS 14, it is unreasonable for this bug to still exist beyond that. This is one of the few major bugs that makes third party browsers, and WebView in general, into second class citizens.
Comment 24 Matt A 2020-07-02 19:26:26 PDT
Hi All, I have been able to speak directly to Apple Engineering via phone (due to the company I work for being involved in their enterprise support developer program) and they have acknowledged the issue however ... I was apparently the first to report this issue to them under their WebKit team. It will be moved up in priority if everyone can lodge a ticket about this issue via https://feedbackassistant.apple.com/ 

Please ensure:
- you specify the bug is on iOS 14 as that is their priority at the moment
- Specify it does not work on 3rd party browsers using WKWebView (i.e. Chrome).

More numbers means we have a better chance of this getting fixed especially as they are looking into iOS 14 bugs more now.
Comment 25 Matt A 2020-07-02 19:28:53 PDT
Also make sure you specify it to be sent to the "WebKit" team, its the last option on the list of departments.
Comment 26 bernie 2020-07-03 01:46:11 PDT
Thanks a lot Matt A, have added a ticket as well.

Their answer is surprising though given this thread: https://bugs.webkit.org/show_bug.cgi?id=185448

It's clearly been worked on in the narrower context of the home screen.

Any chance you could speak to Apple Engineering again and make sure the Webkit team is aware of both threads? Maybe it was somehow a different team that did the home screen work
Comment 27 Eric 2020-07-03 12:30:40 PDT
(In reply to Matt A from comment #24)

Thank you Matt for the suggestion! I did it 👍
To Others: please do it as well to weigh in!

Howto: 
1. You need to use Safari for https://feedbackassistant.apple.com/
  (Chrome won't work, you get a 403)
2. You need to login with your Apple developer account to submit the feedback.
3. Mention iOS 14 in the title
4. Select "WebKit" as area

Here is what I posted in the description:

----


Bug https://bugs.webkit.org/show_bug.cgi?id=208667

This bug is a HUGE problem for several reasons:

1. It prevents ALL Cordova apps and apps relying on WkWebViews to use the WebRTC standard.
   Just because of this bug, we are forced to recommend all our clients to use Android phones & tablets, that's too bad.

2. It prevents ALL other browsers on iOS to offer video-conferencing, while Safari can
   => it's a nasty anti-competitive behaviour that will for sure be scrutinized by US House Antitrust Committee & EU Commission,
   and Apple should not accumulate evidence of evil conduct.

3. More generally speaking, fixing this bug would prove that Apple is committed to W3C standards for WebKit,
   and that WebKit is not a second class citizen in Apple ecosystem.
   Being faster than Chrome on rendering while lagging on standards is pointless.

Good luck for the fix!
Comment 28 Peter 2020-07-03 12:36:47 PDT
Added my own feedback with Apple as well. Thank you.
Comment 29 bizready2009 2020-07-08 05:13:38 PDT
This is really a missing feature. Lots of creativities are blocked by this missing feature. Hope, it gets addressed in release.
Comment 30 acoggins547 2020-07-18 10:06:29 PDT
I'm also experiencing this issue in the context of a WKWebView embedded into my own app.
Comment 31 lorenz.graaf 2020-07-29 02:21:22 PDT
This specific bug is holding us off from promoting apple products to go along with our services. It not only is in the way of simple picture capture, it furthermore prohibits audio recording, video recording, qr (or other code) scans and any other application that would require audio and/or video stream data within the WKWebView.

This bug in itself is a deal-breaker for many when it comes to the choice of an ecosystem.
Comment 32 uhurusurfa 2020-07-31 01:50:21 PDT
Definitely a show stopper for supporting Apple devices where users prefer to use Firefox or Chrome and definitely results in promoting non-apple devices as the preferred device for our platform.
Comment 33 Jeffrey Alan Scudder 2020-08-08 07:24:06 PDT
Lots of people are downloading my new game in the App Store right now, and I can't believe that I have to tell them to go use the website instead if they want to access the beautiful Camera feature I have just added. Please fix this!
Comment 34 Nick 2020-08-22 11:29:58 PDT
+1
Comment 35 uhurusurfa 2020-08-26 01:32:53 PDT
Pretty fundamental piece of functionality missing for a modern app.
Comment 36 Alexander Borsuk 2020-09-06 07:20:18 PDT
Please fix this bug, or provide a usable workaround, at least for WebRTC. WebRTC cam/mic access is required for any app which uses WebRTC.
Comment 37 Yossi 2020-09-16 01:35:35 PDT
+1
Comment 38 Mayowa Daniel 2020-09-17 05:26:59 PDT
Why dooesn't this work yet?
Comment 39 friedrich.waack 2020-09-29 04:38:39 PDT
Browser manufacturers are forced to use WebKit and WebKit disables features that work in Safari? If the antitrust authorities weren't so incompetent then this would be a case for them.

So please fix it in the spirit of fair competition and finally let our apps run on your devices.
Comment 40 frik 2020-09-29 04:56:20 PDT
(In reply to friedrich.waack from comment #39)
> Browser manufacturers are forced to use WebKit and WebKit disables features
> that work in Safari? If the antitrust authorities weren't so incompetent
> then this would be a case for them.
> 
> So please fix it in the spirit of fair competition and finally let our apps
> run on your devices.

Completely agree.  Yet another example of Apple's anti-trust violation.  We should get visibility of this example to law makers.
Comment 41 frik 2020-09-29 04:57:56 PDT
They pretend to give users a choice, but then cripple the alternatives.
Comment 42 Peter 2020-10-08 10:49:20 PDT
How is it possible that this bug still exists post iOS 14 where users are now allowed to change their default browser?
Comment 43 Eric 2020-10-08 11:54:21 PDT
Overall, the SILENCE from APPLE about this CRITICAL issue shows it's an *intentional* anti-competitive practice.

There are no technical excuses that can explain why it would work in Safari and not in WkWebView.

It's a HUGE SHAME that should be sanctioned by authorities.

Please spread the word as widely as possible.