HIDDevice: open() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Note: This feature is available in Web Workers.

The open() method of the HIDDevice interface requests that the operating system opens the HID device.

Note: HID devices are not opened automatically. Therefore, a HIDDevice returned by HID.requestDevice() must be opened with this method before it is available to transfer data.

Syntax

js
open()

Parameters

None.

Return value

A Promise that resolves with undefined once the connection is opened.

Exceptions

InvalidStateError DOMException

Thrown if the connection is already open.

NotAllowedError DOMException

Thrown if the attempt to open the connection fails for any reason.

Examples

In the following example, we wait for the HID connection to open before attempting to send or receive data.

js
await device.open();

Specifications

Specification
WebHID API
# dom-hiddevice-open

Browser compatibility

BCD tables only load in the browser