本文介绍了如何在FireFox中检查访问麦克风的权限是否已被用户拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以找出用户是否拒绝或允许对媒体设备的许可(例如:麦克风,摄像头)在Firefox中?在Chrome中,我可以使用navigator.permissions.query进行检查,但这在Firefox中失败,并显示"TypeError".

Is there a way to find out if the user has rejected or allowed permission to the media devices (Eg:Microphone, Camera) in Firefox?. In Chrome, I can check that with navigator.permissions.query but this fails in Firefox with a "TypeError".

navigator.permissions.query({name:"microphone"}).then(function(promise) {
   if ( promise && promise.state ) {
      console.log(promise.state); //"granted", "prompt" or "rejected"
    }
});
//in Firefox, It throws the error "TypeError: 'name' member of PermissionDescriptor '' is not a valid value for enumeration PermissionName"

由于某种原因,我无法使用try catch块捕获上述错误.所以我想知道为什么我不能在try catch块中以及如果有其他方法的情况下捕获此错误.谢谢你.

I could not catch the above error with a try catch block for some reason. So I would like to know why I can't catch this error in a try catch block and If there is an alternative approach. Thanks in advacne.

用例

我的应用程序具有语音识别功能.在用户遇到寻求访问麦克风的实际系统对话框"之前,我需要显示弹出预许可".此预权限弹出"背后的想法是向用户提供上下文,说明应用程序为何需要访问.如果用户已经授予/拒绝访问权限,则不需要预许可弹出窗口.所以我需要检查麦克风的权限状态,并在需要时显示弹出窗口.

My application has speech recognition feature. I need to show a "Pre permission pop up" before user encounters the actual "System dialog" seeking access to microphone. The idea behind this "pre permission pop up" is to give a context to the user why the application needs the access. If a user has already given/rejected the access then pre permission pop up would not be needed. So I need to check the microphone'spermission state and show the pop up if needed.

推荐答案

不可能

权限API 是一项实验性技术目前正在开发中:

The Permissions API is an experimental technology currently under development:

Mozilla关于权限API的立场

这篇关于如何在FireFox中检查访问麦克风的权限是否已被用户拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:40