Search code examples
javascriptiframeuwpwin-universal-appwebrtc

Get user permission for getUserMedia in iframe within a UWP javascript app


I'm trying to get the user permission dialog to pop up for navigator.getUserMedia, which is called on an external page in an iframe. Currently the sample will show "Permission denied" without ever having presented a dialog to the user.

This is a universal Windows app written in javascript. The webcam has been added to the capabilities.

I've tried finding something similar to the geolocation function below. But I could not find anything for the webcam.

Windows.Devices.Geolocation.Geolocator.requestAccessAsync

The code is very simple. It is an x-ms-webview that links to a webRTC sample.

index.html

<html>
<head>
</head>
<body>
   <x-ms-webview style="left: 0px; top: 0px; width: 100%; height: 100%; position: absolute;" src="https://webrtc.github.io/samples/src/content/getusermedia/gum/"></x-ms-webview>
</body>
</html>

Solution

  • The question has been answered here:
    https://social.msdn.microsoft.com/Forums/office/en-US/16e166d6-fd64-47cf-9e57-560c0d82b6df/how-to-resolve-a-permissiondeniederror-using-webrtc-in-xmswebview?forum=wpdevelop

    You could also use PermissionRequested event to enable the webrtc feature that requires webcam capability. If you use a permission dialog, use WebViewPermissionRequest.Defer to create a WebViewDeferredPermissionRequest which can be used after user input. For more information, please refer to the following links.
    https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/web-view https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/WebView

    document.getElementById("webview").addEventListener("MSWebViewPermissionRequested", managePermissionRequest)
    function managePermissionRequest(e) {
            if (e.permissionRequest.type == "media") {
                    e.permissionRequest.allow();
            }
    }