如何在FireFox中检查访问麦克风的权限是否已被用户拒绝 [英] How to check if the permission to access microphone has been rejected by the user in FireFox

查看:628
本文介绍了如何在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's permission state and show the pop up if needed.

推荐答案

不可能

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

The Permissions API is an experimental technology currently under development:

Mozilla认为,具有用户权限的功能对于用户代理至关重要.该API的某些方面不适用于Firefox中使用的权限模型,因此我们希望在API的几个方面进行改进.特别是,我们认为权限状态需要更准确地反映已存在或可能存在的不同状态的方式.我们还认为与功能策略的交互需要更好地阐明.我们致力于解决此问题,因为权限对于使网络成为功能更强大的平台至关重要,并且确保我们保留用户对其在线体验的控制权非常重要

Mozilla believes that the ability to work with user permissions is critical for user agency. There are certain aspects of the API that are not suitable for the permissions model used in Firefox and so we would like to work on improving several aspects of the API. In particular, we think that the way that status of permissions needs to more accurately reflect the different states that exist or could exist. We also think that the interactions with Feature Policy need to be better clarified. We're committed to fixing this, because permissions has become critical in making the web a more capable platform and it is important to ensure that we preserve user control over their online experience

Mozilla关于权限API的立场

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆