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.
如果我们在Chrome网站上运行HTML5的Web Speech API的JavaScript代码,则Chrome会要求用户允许使用用户计算机的麦克风。
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?
但是,如果我在Chrome扩展程序页面上运行上述代码,则Chrome不会要求用户授予权限。 Chrome扩展程序如何获得用户使用用户计算机麦克风的权限?
Thank you.
谢谢。
2 个解决方案
#1
-1
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.
我想你必须自己实现它。在chrome扩展的manifest.json中,有一个权限参数。我想首先你必须获得在该文件中使用麦克风的权限。我不知道调用的参数是什么,但您可以在文档中查看。
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.
仅当用户安装扩展时,才会显示此权限警告。之后,扩展可以按照其意愿打开/关闭麦克风。要获得用户的许可,请先检查用户正在使用的网站,以及是否要激活该麦克风。之后,只需在该网页中注入HTML / CSS代码,该代码将向用户显示弹出窗口,要求获得她的许可。如果权限为是,请将消息发送到后台页面,然后将其打开。
#2
0
You can use the navigator
global object to ask for audio and/or video permission in your JS file of your chrome extension:
您可以使用导航器全局对象在Chrome扩展的JS文件中请求音频和/或视频权限:
navigator.getUserMedia({audio: true, video: true})
although MDN says it's deprecated you can use this instead:
虽然MDN说它已被弃用,但您可以使用它:
navigator.mediaDevices.getUserMedia({audio: true})
Check this tutorial as well for some alternatives to JS.
查看本教程以及JS的一些替代方法。
#1
-1
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.
我想你必须自己实现它。在chrome扩展的manifest.json中,有一个权限参数。我想首先你必须获得在该文件中使用麦克风的权限。我不知道调用的参数是什么,但您可以在文档中查看。
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.
仅当用户安装扩展时,才会显示此权限警告。之后,扩展可以按照其意愿打开/关闭麦克风。要获得用户的许可,请先检查用户正在使用的网站,以及是否要激活该麦克风。之后,只需在该网页中注入HTML / CSS代码,该代码将向用户显示弹出窗口,要求获得她的许可。如果权限为是,请将消息发送到后台页面,然后将其打开。
#2
0
You can use the navigator
global object to ask for audio and/or video permission in your JS file of your chrome extension:
您可以使用导航器全局对象在Chrome扩展的JS文件中请求音频和/或视频权限:
navigator.getUserMedia({audio: true, video: true})
although MDN says it's deprecated you can use this instead:
虽然MDN说它已被弃用,但您可以使用它:
navigator.mediaDevices.getUserMedia({audio: true})
Check this tutorial as well for some alternatives to JS.
查看本教程以及JS的一些替代方法。