HIDDevice: open() method

فهرست فصل‌ها دانلود آرشیوناشر

MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونه‌کد

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers("window_and_worker_except_shared")}}

The **open()** method of the {{domxref("HIDDevice")}} interface requests that the operating system opens the HID device.

توجه: HID devices are not opened automatically. Therefore, a {{domxref("HIDDevice")}} returned by {{domxref("HID.requestDevice()")}} must be opened with this method before it is available to transfer data.

Syntax

js-nolint
open()

Parameters

None.

Return value

A {{jsxref("Promise")}} that resolves with undefined once the connection is opened.

Exceptions

  • InvalidStateError {{domxref("DOMException")}}
  • : Thrown if the connection is already open.
  • NotAllowedError {{domxref("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

{{Specifications}}

Browser compatibility

{{Compat}}