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


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


        result => console.log('Has permission?',result.hasPermission),
        err => this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.CAMERA)


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


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


"scripts": [

In my web use api

function startVideo() {
     const constraints = { audio: false, video: { facingMode: "user" } }
     .then(function(mediaStream) { = mediaStream; 
     video.srcObject = mediaStream;
     video.onloadedmetadata = function(e) {
     .catch(function(err) { showAlert( + ": " + 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

Was you able to resolve this issue? I have the same problem

Hi, if you use inappbrowser, set the option to _self it will work