Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if the permission to access microphone has been rejected by the user in FireFox

Tags:

Is there a way to find out if the user has rejected or allowed permission to the media devices (Eg: Microphone, Camera) in Firefox?. In Chrome, I can check that with navigator.permissions.query but this fails in Firefox with a "TypeError".

navigator.permissions.query({name:"microphone"}).then(function(promise) {
   if ( promise && promise.state ) {
      console.log(promise.state); //"granted", "prompt" or "rejected"
    }
});
//in Firefox, It throws the error "TypeError: 'name' member of PermissionDescriptor '' is not a valid value for enumeration PermissionName"

I could not catch the above error with a try catch block for some reason. So I would like to know why I can't catch this error in a try catch block and If there is an alternative approach.

Use Case

My application has speech recognition feature. I need to show a "Pre permission pop up" before user encounters the actual "System dialog" seeking access to microphone. The idea behind this "pre permission pop up" is to give a context to the user why the application needs the access. If a user has already given/rejected the access then pre permission pop up would not be needed. So I need to check the microphone's permission state and show the pop up if needed.

like image 602
Murali Nepalli Avatar asked Dec 02 '19 00:12

Murali Nepalli


1 Answers

It's not possible

The Permissions API is an experimental technology currently under development:

Mozilla believes that the ability to work with user permissions is critical for user agency. There are certain aspects of the API that are not suitable for the permissions model used in Firefox and so we would like to work on improving several aspects of the API. In particular, we think that the way that status of permissions needs to more accurately reflect the different states that exist or could exist. We also think that the interactions with Feature Policy need to be better clarified. We're committed to fixing this, because permissions has become critical in making the web a more capable platform and it is important to ensure that we preserve user control over their online experience

Mozilla's position about Permissions API

like image 178
Temo Tchanukvadze Avatar answered Oct 18 '22 12:10

Temo Tchanukvadze