这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
安全上下文
此特征只可用于
安全上下文
(HTTPS),在某些或所有
支持浏览器
.
getDevices
方法在
USB
interface returns a
Promise
that resolves with an array of
USBDevice
objects for paired attached devices. For information on pairing devices, see
USB.requestDevice()
.
USB.getDevices()
None.
A
Promise
that resolves with an array of
USBDevice
对象。
The following example logs the product name and serial number of paired devices to the console. For information on pairing devices, see
USB.requestDevice()
.
navigator.usb.getDevices()
.then(devices => {
console.log("Total devices: " + devices.length);
devices.forEach(device => {
console.log("Product name: " + device.productName + ", serial number " + device.serialNumber);
});
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebUSB
The definition of 'getDevices' in that specification. |
草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
getDevices
|
Chrome 61 | Edge 79 | Firefox No | IE No | Opera 48 | Safari No | WebView Android No | Chrome Android 61 | Firefox Android No | Opera Android 45 | Safari iOS No | Samsung Internet Android 8.0 |
完整支持
不支持
实验。期望将来行为有所改变。
USB
getDevices()
onconnect
ondisconnect
requestDevice()