-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
48 lines (33 loc) · 1.03 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
---
title: "HID: getDevices() method"
short-title: getDevices()
slug: Web/API/HID/getDevices
page-type: web-api-instance-method
status:
- experimental
browser-compat: api.HID.getDevices
---
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
The **`getDevices()`** method of the {{domxref("HID")}} interface gets a list of the 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
document.addEventListener("DOMContentLoaded", async () => {
let devices = await navigator.hid.getDevices();
devices.forEach((device) => {
console.log(`HID: ${device.productName}`);
});
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}