Question

If we run HTML5's Web Speech API's JavaScript codes below in a website on a Chrome, Chrome will ask for user's permission for the use of user's computer's microphone.

var recognition = new webkitSpeechRecognition();
recognition.start();

But if I run codes above on a Chrome extension's page, Chrome doesn't ask users to give a permission. How can a Chrome extension get a user's permission to use user's computer's microphone?

Thank you.

Was it helpful?

Solution

I think you have to implement it yourself. In chrome extension's manifest.json, there is a permissions parameter. I think first you have to get the permission to use microphone in that file. I don't know what is the parameter called but you can check that in the documentation.

This permission warning is shown only when the user installs the extension. After that, the extension can turn microphone on/off at its volition. To seek permission from user, first check which website user is using and if you want to activate the microphone on that. After that, just inject HTML/CSS code in that webpage that will show a popup to user asking for her permission. If the permission is yes, send the message to background page and then just turn it on.

OTHER TIPS

You can use the navigator global object to ask for audio and/or video permission in your JS file of your chrome extension:

navigator.getUserMedia({audio: true, video: true})

although MDN says it's deprecated you can use this instead:

navigator.mediaDevices.getUserMedia({audio: true})

Check this tutorial as well for some alternatives to JS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top