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?

Advertisements

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.

>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;
}

Leave a ReplyCancel reply