HID:getDevices() 方法
        
        
          Limited availability
        
        
        
          
                
              
                
              
                
              
        
        
      
      This feature is not Baseline because it does not work in some of the most widely-used browsers.
备注: 此特性在 Web Worker(不包括共享 Web Worker)中可用。
HID 接口的 getDevices() 方法获取一个包含用户之前已通过 requestDevice() 调用授予访问权限的已连接 HID 设备列表。
语法
js
getDevices()
参数
无。
返回值
示例
以下示例获取设备列表并将设备名称记录到控制台。
js
document.addEventListener("DOMContentLoaded", async () => {
  let devices = await navigator.hid.getDevices();
  devices.forEach((device) => {
    console.log(`HID:${device.productName}`);
  });
});
规范
| Specification | 
|---|
| WebHID API> # dom-hid-getdevices>  | 
            
浏览器兼容性
Loading…