Back to Content

HID: getDevices() method

files/en-us/web/api/hid/getdevices/index.md

latest840 B
Original Source

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

The getDevices() method of the {{domxref("HID")}} interface gets a list of connected HID devices that the user has previously been granted access to in response to a {{domxref("HID.requestDevice","requestDevice()")}} call.

Syntax

js-nolint
getDevices()

Parameters

None.

Return value

A {{jsxref("Promise")}} that resolves with a list of {{domxref("HIDDevice")}} objects.

Examples

The following example gets a list of devices and logs the device names to the console.

js
let devices = await navigator.hid.getDevices();
devices.forEach((device) => {
  console.log(`HID: ${device.productName}`);
});

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}