权限基础结构是否支持 WebUSB?

Does WebUSB is supported by permissions infrastructure?

WebUSB API 文档向权限基础结构 (https://wicg.github.io/webusb/#permission-api) 引入了名为“usb”的新强大功能。但是当我尝试使用权限 api 来查询“usb”的权限时:

navigator.permissions.query({name:'usb'})

我收到错误:

TypeError: Failed to execute 'query' on 'Permissions': The provided value 'usb' is not a valid enum value of type PermissionName.

我在 Ubuntu 上使用 Chrome 版本 83.0.4103.97(官方构建)(64 位)。我的第一个问题:

  1. 权限api是否支持“usb”功能?如果是,我在上面的代码中做错了什么?

WebUSB 规范定义了允许设备的存储位置,但据我所知,它再次提供使用权限基础结构 (https://wicg.github.io/webusb/#request-the-usb-permission)。我的第二个问题:

  1. 如果权限api还不支持“usb”功能,where/how允许的设备存储在浏览器中?我可以通过编程方式访问此存储吗?

  2. 网站能否请求用户允许访问不仅现在连接而且将来也可以连接的设备组(在我的例子中是 vid+pid)?换句话说,我想问用户“请让我使用你将来连接的 usb 设备(使用这个 vid+pid),因为我不想在你每次连接新设备时都问权限问题让你厌烦特定类型。

  1. Does permissions api support "usb" feature? If yes, what I do wrong in upper code?

没有。虽然规范中定义的 Permissions API 集成是在基于 Chromium 的浏览器中实现的,但它不会通过 Permissions API 的 query() 方法公开。 issue 638721 对此进行了跟踪,但考虑到可用的替代方案,这并不是优先事项。

  1. If permissions api not yet support "usb" feature, where/how allowed devices are stored in browser? Can I programmatically get access to this storage?

权限存储在浏览器的用户首选项文件和内部数据结构中,Javascript 无法直接访问这些文件。目前公开这些权限的唯一方法是通过设置 UI (chrome://settings/content/usbDevices) 和 navigator.usb.getDevices() 方法,只有 returns 允许设备,如果他们目前已连接。

  1. Can website request user to allow permissions to group of devices (in my case by vid+pid) which not only connected right now, but also can be connected in future? In other words, I want to ask user "Please, let me work with usb devices (with this vid+pid) which you connect in a future, because I don't want to bore you with permission question every time you connect new device of particular type".

没有。用户根据当前连接的设备而不是假设的未来设备做出决定,这对 API 的安全设计很重要。

对于企业管理的设备,WebUsbAllowDevicesForUrls 策略允许管理员代表他们的用户做出此类决定。