22

I have a URL that is working fine with Safari on iOS11 (Beta) Audio/Video is working fine. But when I load this URL with WKWebView it gives me an error "Incompatible Browser" and when I check my browser version in WebKit it shows "WebKit based browser on iOS 11"

So the question really is, has Apple included this change in the WKWebview webkit (which should be the same as Safari) for the developer BETA of iOS 11?

devanshu_kaushik
  • 929
  • 11
  • 30
adarshk
  • 338
  • 1
  • 2
  • 10
  • I see the same symptom using the tokbox web sdk. Initial feedback from tokbox is to "not expect" support of webrtc in WKWebview. I've asked for definitive confirmation (ideally from Apple). – steve1951 Jul 21 '17 at 11:09
  • @steve1951 did you ever get any official word on WebRTC support in a WebView? – Dobes Vandermeer Oct 12 '17 at 19:33
  • nothing official, but upon more attentive reading Apple seems to go out of their way to state webrtc is available in Safari with no mention of WKWebview. – steve1951 Oct 13 '17 at 21:04
  • I answered Yes - It's supported - since it is more updated information. Consider selecting new Answer for this one? – zaxy78 Apr 17 '18 at 22:18

3 Answers3

39

Update: WebRTC Support is coming in iOS14.3 (Beta)

Learn more here: https://webkit.org/blog/11353/mediarecorder-api/

From iOS11+ :

WebRTC is partially supported in WKWebView,
and fully supported in the Safari App browser.


Explained:

WebRTC has three main JavaScript APIs:

  • MediaStream (aka getUserMedia)
  • RTCPeerConnection
  • RTCDataChannel

For apps running inside Safari App, iOS11+, all WebRTC APIs are supported. That includes getUserMedia. Be sure to use adapter.js library for best compatibility, since each browser - including Safari - uses a different name for its implementation. For example, in Safari it's navigator.mediaDevices.getUserMedia().

But, when using WKWebView or SFSafariViewController, it's a different story:

You can still stream video & audio from local storage or consume live media captured by a peer. Hopefully in iOS 12 we'll see some progress...

zaxy78
  • 1,406
  • 3
  • 19
  • 32
  • 4
    Got any citations for this? – hipkiss Apr 16 '18 at 13:20
  • Works on both iPhone & iPads. source: https://webkit.org/blog/7726/announcing-webrtc-and-media-capture/ – zaxy78 Apr 17 '18 at 22:12
  • I was hoping for more on the "getUserMedia" not supported. I'm trying to get webRTC to work in safari on iphone. Currently it's intermittent at best. – hipkiss Apr 18 '18 at 08:20
  • It's for security reasons. it takes the Apple team approx. ~1 year to fully support new features from WebKit inside the WKWebView... it was released on June'17 so stay tuned... – zaxy78 Apr 23 '18 at 12:08
  • I meant Native safari, not the webview inside apps. Does your statement still hold true for the safari ios browser? – hipkiss Apr 23 '18 at 12:20
  • 1
    I understand now, see me updated answer. (yes it works; but use adapter.js from https://github.com/webrtc/adapter) – zaxy78 Apr 24 '18 at 07:37
  • 1
    I've been using WebRTC in production in a WkWebView for a while now - it works (RTCDataChannel). tvOS is baffling though - no way to use WebRTC there without bringing your own libwebrtc. – Benjamin Gruenbaum Apr 24 '18 at 09:41
  • The issue is listed on Open Radar, the (unofficial) Apple issue tracker. http://www.openradar.me/33571214 "getUserMedia not supported in WKWebView" – Pierre F May 24 '18 at 12:15
  • getUserMedia not being available in WKWebView is also the reason why other browsers such as Chrome won't have access to the camera e.g. for video chat solutions. https://bugs.chromium.org/p/chromium/issues/detail?id=752458 – Pierre F May 24 '18 at 12:16
  • 2
    The topic was discussed on the Apple Developer Forums and most probably, WKWebView won't provide support for getUserMedia until the next "major OS release", i.e. not before iOS 12 around September 2018. https://forums.developer.apple.com/thread/88052#thread-post-278803 – Pierre F May 24 '18 at 12:19
  • seems like there might be a workaround to enabled getUserMedia() using WebKit APIs. see this comment on OpenRedar: http://www.openradar.me/33571214 – zaxy78 Oct 14 '18 at 11:41
  • 4
    iOS 12 is now out, and it appears that getUserMedia is still not supported in WKWebView. In Chrome 70 for iOS (which uses WKWebView), navigator.mediaDevices.getUserMedia is undefined. – Derrick Miller Oct 27 '18 at 01:18
  • 3
    Is there any way to pass the RTCMediaStream from native code to wkwebview? – WorieN Dec 29 '18 at 12:18
  • @WorieN have you tried using WebRTC itself to send it to itself on 127.0.0.1, you don't even need a signaling server? – Gregory Magarshak Jun 25 '19 at 21:22
  • @zaxy78 can u please update the answer about the status in iOS 12 and 13? – Amos Aug 12 '19 at 05:38
  • 1
    Still no getUserMedia support as of iOS 13.2 – RealHandy Dec 11 '19 at 22:27
  • 1
    iOS 14.3 started supporting `getUserMedia()` – Almas Adilbek Jan 13 '21 at 07:08
9

I did a bit of digging in the WebKit sources last night, and it looks like the WebRTC/MediaCapture stuff is all gated behind a preference that's only accessible via a private API. There was also a commit that mentioned something about apps needing to handle all the setup for A/V permissions.

In any case, the result is that getUserMedia doesn't work in WKWebView, even on iOS11 (beta 4, at least) :(

I've filed a radar (rdar://33571214 and http://www.openradar.me/33571214) and encourage everyone else to do the same.

dpogue
  • 553
  • 5
  • 7
  • 1
    I managed to access the private API and accept camera permission request by following this test https://github.com/WebKit/webkit/blob/5e250ba19a76ccf164d1d31e6a49700bab34826e/Tools/TestWebKitAPI/Tests/WebKitCocoa/UserMediaDisabled.mm . I can run the mock media capture but i still can't get a live camera capture, i get this error "Could not create a 'com.apple.webkit.camera' sandbox extension". Do you have any idea how to get pass this error? – Zhong Huiwen Oct 01 '17 at 18:29
  • Did you succeed? I'm also looking to activate sound and video in my project via getUserMedia. How can I access the Private API? My project is in swift – Mickael Belhassen May 06 '20 at 10:19
3

I have done some tests with iOS Beta 4 and it seems that even WKWebview nor UIWebview don't support getUserMedia as a WebRTC API.

Can someone confirm this?

Daniel Toplak
  • 325
  • 2
  • 10