HID: getDevices() method
MDN Web Docs · نسخهٔ df622a2a1c1e · CC BY-SA 2.5 و مجوز جداگانهٔ ناشر برای نمونهکد
{{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}}