7

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.

2 Answers 2

6

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.

1
  • 1
    It also works for me but my requirement to get user media permissions like allowed, denied and prompt(ask default). Are you able to get navigator.permissions.query in firefox??
    – anshdeep
    Commented Nov 30, 2018 at 8:10
4

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

1
  • 1
    No problem! If you find a solution/workaround for this by yourself, feel free to add an aswer to your own question, otherwise, consider accepting an answer to your question if it suits you :)
    – Stephan T.
    Commented Nov 30, 2018 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.