navigator.mediaDevices.getUserMedia doesn't work on macos catalyst WKWebView

161 Views Asked by At

I've got the following error on Mac Catalyst WKWebView:

TypeError: undefined is not an object (evaluating 'navigator.mediaDevices.getUserMedia')

macOS 13.5.1 (22G 90) Safari 17.0 (18616.1.24.11.5, 18616) UserAgent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15"

The same app works well on iOS.

I have added native checks for camera and microphone access. If they are not available, I make a request. After both are approved, checkboxes appear in the privacy settings of macOS. However, I still receive the same error. Interestingly, iOS does not have any access checks; the request is automatically initiated, presumably by Safari.

1

There are 1 best solutions below

0
Alex Titarenko On

I found a solution which works for me:

config.preferences.setValue(true, forKey: "mediaDevicesEnabled")

Where config is an instance of WKWebViewConfiguration