USB

这是 实验性技术
检查 浏览器兼容性表格 在生产中使用这之前。

Secure context
This feature is available only in secure contexts (HTTPS), in some or all supporting browsers .

USB interface of the WebUSB API provides attributes and methods for finding and connecting USB devices from a web page.

特性

None.

事件处理程序

USB.onconnect
An event handler called whenever a previously paired device is connected.
USB.ondisconnect
An event handler called whenever a paired device is disconnected.

方法

USB.getDevices()
Returns a Promise that resolves with an array of USBDevice objects for paired attached devices.
USB.requestDevice()
返回 Promise that resolves with an instance of USBDevice if the specified device is found. Calling this function triggers the user agent's pairing flow.

规范

规范 状态 Comment
WebUSB
The definition of 'USB' in that specification.
草案 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
USB
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
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
onconnect
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
ondisconnect
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
requestDevice
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

图例

完整支持
完整支持
不支持
不支持
实验。期望将来行为有所改变。
实验。期望将来行为有所改变。