How to trigger microphone permission popup on chrome (javascript)

18,854

You need to get the permission using the navigator object.

navigator.mediaDevices.getUserMedia({ audio: true })
      .then(function(stream) {
        console.log('You let me use your mic!')
      })
      .catch(function(err) {
        console.log('No mic for you!')
      });

Also you need to run it on HTTPS and on a website instead of using IP addresses

Share:
18,854

Related videos on Youtube

Hakan
Author by

Hakan

https://github.com/hakanozkaptan

Updated on June 13, 2022

Comments

  • Hakan
    Hakan almost 2 years

    How can i trigger this modal on javascript button click

    enter image description here

  • saudblaze
    saudblaze about 4 years
    It shows in console but how can we show modal to user .
  • Saransh Kataria
    Saransh Kataria about 4 years
    you need to replace the console.log logic with whatever you use to show modals
  • aspiring1
    aspiring1 almost 4 years
    @SaranshKataria : I have some javascript code in my flask webserver, when I run it on localhost, I can record easily. But when the code is on the server, when I press the button for Record, I don't see any recording start, do I need to run it on HTTPS instead of HTTP and on a website? Isn't HTTPS more about being secure?
  • Saransh Kataria
    Saransh Kataria almost 4 years
    @aspiring1 since media and camera are powerful features, the web standards enforce them to work only on HTTPS websites. You can read more about it on developer.mozilla.org/en-US/docs/Web/API/MediaDevices/…
  • CodeZila
    CodeZila about 3 years
    The popup in my chrome browser has Allow and Block buttons interchanged. Any browser setting for that?