How to trigger microphone permission popup on chrome (javascript) [duplicate]
Asked Answered
C

1

8

How can i trigger this modal on javascript button click

enter image description here

Capers answered 28/6, 2018 at 8:28 Comment(1)
@Capers just a note – it's navigator.mediaDevices.getUserMedia now (used to be just navigator.getUserMedia)Seat
D
18

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

Drypoint answered 28/6, 2018 at 8:31 Comment(5)
It shows in console but how can we show modal to user .Candless
you need to replace the console.log logic with whatever you use to show modalsDrypoint
@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?Scharaga
@Scharaga 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/…Drypoint
The popup in my chrome browser has Allow and Block buttons interchanged. Any browser setting for that?Bim

© 2022 - 2024 — McMap. All rights reserved.