MediaDevices.getUserMedia() permission denied in webview while camera is allowed

Hi everyone, I’m trying to use MediaDevices.getUserMedia() api in my webview app, but after a lot of effort I keep getting “permission denied” error even though camera access is allowed, here is what i added

app.module.ts

import { AndroidPermissions } from '@ionic-native/android-permissions/ngx';
...
providers: [    
AndroidPermissions,
]

app.component.ts

this.androidPermissions.checkPermission(this.androidPermissions.PERMISSION.CAMERA).then(
        result => console.log('Has permission?',result.hasPermission),
        err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.CAMERA)
      );
      
      this.androidPermissions.requestPermissions([this.androidPermissions.PERMISSION.CAMERA]);

config.xml

<plugin name="cordova-plugin-android-permissions" spec="1.1.2" />

AndroidManifest.xml

<uses-permission android:name="android.permission.CAMERA" />

angular.json

"scripts": [
              "node_modules/webrtc-adapter/out/adapter.js"
            ]

In my web use api

function startVideo() {
     const constraints = { audio: false, video: { facingMode: "user" } }
     navigator.mediaDevices.getUserMedia(constraints)
     .then(function(mediaStream) {
     window.stream = mediaStream; 
     video.srcObject = mediaStream;
     video.onloadedmetadata = function(e) {
               video.play();
      };
     })
     .catch(function(err) { showAlert(err.name + ": " + err.message); });
}

It working on browser but not in my ionic app
Can anyone point out where I am missing?

I’ve tried your code and it’s working fine on my device.
You don’t even need to request the permission, that’s handled by the WebView as long as you have it in the AndroidManifest.xml

I’m not sure how relevant this is, but there are two words I see in your snippet that I don’t like seeing in Ionic apps: window and function.

A better alternative to polluting window is to use service providers to communicate across parts of the app. Arrow functions are more robust than old-school function functions, protecting you from situations where this isn’t what you think it is.

I’m similarly nervous about the reference to an off-screen video variable that is presumably some other global.

I still don’t understand why I get permission error on both my android devices even though I see permission is allowed