USB

Experimental: 这是一个实验中的功能
此功能某些浏览器尚在开发中,请参考浏览器兼容性表格以得到在不同浏览器中适合使用的前缀。由于该功能对应的标准文档可能被重新修订,所以在未来版本的浏览器中该功能的语法和行为可能随之改变。

WebUSB API (en-US) 接口提供了从网页查找和连接 USB 设备的属性和方法

属性

None.

Event handlers

USB.onconnect (en-US)

每当连接到先前配对的设备时,调用此事件处理器。

USB.ondisconnect (en-US)

每当配对设备断开连接时,调用此事件处理器。

方法

USB.getDevices() (en-US)

Returns a Promise that resolves with an array of USBDevice (en-US) objects for paired attached devices.

USB.requestDevice() (en-US)

Returns a Promise that resolves with an instance of USBDevice (en-US) if the specified device is found. Calling this function triggers the user agent's pairing flow.

规范

Specification
WebUSB API
# usb

Browser compatibility

BCD tables only load in the browser