Search code examples
javascriptuwpwin-universal-appwebrtcwinjs

Issue with Using WebRTC getUserMedia with UWP WebView


I've created a basic UWP application with a WebView. I'm navigating to this URL: https://webrtc.github.io/samples/src/content/getusermedia/gum/ to test the use of getUserMedia().

The error I get is:

getUserMedia error: NotFoundError

I have also add Capabilities Webcam capability to enable the Camera device for your app. but no luck.

Does anyone know if this should be possible, and if I'm therefore doing something wrong? Anyone using getUserMedia within a UWP WebView?


Solution

  • You need allow PermissionRequest in PermissionRequested event handler.

    In addition to the app handling the PermissionRequested event, the user will have to approve standard system dialogs for apps requesting location or media capabilities in order for these features to be enabled

    MyWebView.PermissionRequested += MyWebView_PermissionRequested;
    
    private void MyWebView_PermissionRequested(WebView sender, WebViewPermissionRequestedEventArgs args)
    {
        if (args.PermissionRequest.PermissionType == WebViewPermissionType.Media)
        {
            args.PermissionRequest.Allow();
        }
    }
    

    Update For WinJS app, you could refer this document.

    document.getElementById('live-preview').addEventListener("MSWebViewPermissionRequested", permissionRequestedEventArgs => {
        const permissionRequest = permissionRequestedEventArgs.permissionRequest;
        switch (permissionRequest.type) {
            case "geolocation":
            case "media":
                permissionRequest.allow();
                break;
            case "pointerlock":
            case "webnotifications":
            case "screen":
            case "immersiveview":
            case "unlimitedIndexedDBQuota":
            default:
                permissionRequest.deny();
                break;
        }
    });