gpt4 book ai didi

javascript - 如何检查访问麦克风的权限是否已被 FireFox 中的用户拒绝

转载 作者:行者123 更新时间:2023-12-03 16:52:29 25 4
gpt4 key购买 nike

有没有办法查明用户是否拒绝或允许媒体设备的权限(例如:
Firefox 中的麦克风、相机)?在 Chrome 中,我可以使用 navigator.permissions.query 进行检查,但在 Firefox 中失败并显示“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 block 捕获上述错误。所以我想知道为什么我不能在 try catch block 中捕捉到这个错误,以及是否有替代方法。
用例
我的应用程序具有语音识别功能。在用户遇到寻求访问麦克风的实际“系统对话框”之前,我需要显示“预许可弹出窗口”。这个“预许可弹出”背后的想法是为用户提供应用程序需要访问权限的上下文。如果用户已经授予/拒绝访问权限,则不需要弹出预许可。所以我需要检查麦克风的
权限状态并在需要时显示弹出窗口。

最佳答案

不可能

Permissions 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's position about Permissions API

关于javascript - 如何检查访问麦克风的权限是否已被 FireFox 中的用户拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59131286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com