HID: phương thức getDevices()

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, except for Shared Web Workers.

getDevices() là phương thức của giao diện HID lấy danh sách các thiết bị HID đang kết nối mà người dùng trước đó đã cấp quyền truy cập thông qua lệnh gọi requestDevice().

Cú pháp

js
getDevices()

Tham số

Không có.

Giá trị trả về

Một Promise phân giải thành một danh sách các đối tượng HIDDevice.

Ví dụ

Ví dụ sau lấy danh sách thiết bị và ghi tên thiết bị ra console.

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

Thông số kỹ thuật

Specification
WebHID API
# dom-hid-getdevices

Tương thích trình duyệt