anshdeep
anshdeep

Reputation: 71

How can I get user media permissions(camera and microphone) of Firefox browser through JavaScript code?

The code below is working properly in the chrome browser:

For microphone:

 navigator.permissions.query({name: 'microphone'})
    .then((permission) => {
        console.log("microphone state", permission.state);
    }).catch((error) => {
        console.log('Got error :', error);
    })

For camera:

 navigator.permissions.query({name: 'camera'})
    .then((permission) => {
        console.log("camera state", permission.state);
    }).catch((error) => {
        console.log('Got error :', error);
    })

The same code above is not working in the Firefox browser where I am getting the following errors:

For microphone: Got error:

TypeError: "'name' member of PermissionDescriptor 'microphone' is not a valid value for enumeration PermissionName."

enter image description here

For camera: Got error:

TypeError: "'name' member of PermissionDescriptor 'camera' is not a valid value for enumeration PermissionName."

Anyone having an idea how to get the user media permission state for camera and microphone in the Firefox browser?

Thanks.

Upvotes: 7

Views: 15256

Answers (2)

uruk
uruk

Reputation: 1316

I did something similar recently, and it worked on Firefox:

navigator.mediaDevices.getUserMedia( { audio: true, video: false } )
   .then( ( stream ) => {
        // microphone available
   },
   e => {
        // microphone not available
   } );

Taken from here.

Upvotes: 6

Stephan T.
Stephan T.

Reputation: 6074

According to this issue on GitHub (specifically this comment), Firefox simply doesn't support camera and microphone.

There are some reasons for this, which are probably too technical, so this feature you are trying to implement is not achievably at the moment (until Firefox figures it out)

Best regards <3

Upvotes: 4

Related Questions