is there any way to get the "Allow" button click event in "Allow to use microphone popup"(chrome latest)?

Viewed 716

i am trying to figure out how could i get the event of the "Allow" button and "Cancel" which pops up near the TLS lock icon , i searched online but couldn't found any articles on this in javascript ?

i am using chrome speechrecognition API Does anyone have any idea ?

1 Answers

I don't think you can get the buttons events.

You can, however, detect the change in permission using the Permission API

Here's an example:

navigator.permissions.query(
    { name: 'microphone' }
).then(function(permissionStatus){
    console.log("Current state: " + permissionStatus.state)

    permissionStatus.onchange = function(){
      if (this.state == "granted") {
        console.log("Allow");
      } else if (this.state == "denied") {
        console.log("Block");
      } else if (this.state == "prompt") {
        console.log("Ask");
      }
    }
})
Related