Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In js is it possible to check if mic permission is given or not in browser or in which state it is or it is blocked by some extension?

Currently I am working on a project and here I can’t it cause problem when permission is in prompt state . Is it possible to get the state of permission in JavaScript code ?

Actually If i get the acess of this then with the help of this I can show proper messages to the customer regarding that.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This can be easily this as :

// Check if microphone permission is granted
function checkMicrophonePermission() {
  var permission = navigator.permissions.query({name: 'microphone'});
  return permission.state === 'granted';
}

function checkMicrophonePermission() {
  var permission = navigator.permissions.query({name: 'microphone'});
  if(permission.state == "prompt"){
    // Do something
  }
}

// Check if microphone permission is blocked by an extension
function checkMicrophonePermissionBlockedByExtension() {
  var extensions = chrome.extensions.getInstalledExtensions();
  for (var i = 0; i < extensions.length; i++) {
    if (extensions[i].permissions && extensions[i].permissions.indexOf('microphone') !== -1) {
      return true;
    }
  }
  return false;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading