<br />

<br />

## Description

Use the `chrome.hid` API to interact with connected HID devices. This API provides access to HID operations from within the context of an app. Using this API, apps can function as drivers for hardware devices. Errors generated by this API are reported by setting [`runtime.lastError`](https://developer.chrome.com/docs/apps/runtime/#property-lastError) and executing the function's regular callback. The callback's regular parameters will be undefined in this case.

<br />

<br />

## Permissions

`hid`  

<br />

<br />

<br />

<br />

## Types

### DeviceFilter

#### Properties

- productId number optional

  Device product ID, checked only if the vendor ID matches.
- usage number optional

  HID usage identifier, checked only if the HID usage page matches.
- usagePage number optional

  HID usage page identifier.
- vendorId number optional

  Device vendor ID.

### GetDevicesOptions

#### Properties

- filters [DeviceFilter](https://developer.chrome.com/docs/apps/reference/hid#type-DeviceFilter)\[\] optional

  A device matching any given filter will be returned. An empty filter list will return all devices the app has permission for.
- productId number optional
  Deprecated

  Equivalent to setting [`DeviceFilter.productId`](https://developer.chrome.com/docs/apps/reference/hid#property-DeviceFilter-productId).

  <br />

- vendorId number optional
  Deprecated

  Equivalent to setting [`DeviceFilter.vendorId`](https://developer.chrome.com/docs/apps/reference/hid#property-DeviceFilter-vendorId).

  <br />

### HidCollectionInfo

#### Properties

- reportIds number\[\]

  Report IDs which belong to the collection and to its children.
- usage number

  Page-defined usage identifier.
- usagePage number

  HID usage page identifier.

### HidConnectInfo

#### Properties

- connectionId number

  The opaque ID used to identify this connection in all other functions.

### HidDeviceInfo

#### Properties

- collections [HidCollectionInfo](https://developer.chrome.com/docs/apps/reference/hid#type-HidCollectionInfo)\[\]

  Top-level collections from this device's report descriptors.
- deviceId number

  Opaque device ID.
- maxFeatureReportSize number

  Top-level collection's maximum feature report size.
- maxInputReportSize number

  Top-level collection's maximum input report size.
- maxOutputReportSize number

  Top-level collection's maximum output report size.
- productId number

  Product ID.
- productName string
  Chrome 46+

  The product name read from the device, if available.
- reportDescriptor ArrayBuffer

  Raw device report descriptor (not available on Windows).
- serialNumber string
  Chrome 46+

  The serial number read from the device, if available.
- vendorId number

  Vendor ID.

## Methods

### connect()

Promise

```typescript
chrome.hid.connect(
  deviceId: number,
  callback?: function,
): Promise<https://developer.chrome.com/docs/apps/reference/hid#type-HidConnectInfo>
```

Open a connection to an HID device for communication.

#### Parameters

- deviceId number

  The [`HidDeviceInfo.deviceId`](https://developer.chrome.com/docs/apps/reference/hid#property-HidDeviceInfo-deviceId) of the device to open.
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (connection: HidConnectInfo) => void
  ```

  <br />

  - connection [HidConnectInfo](https://developer.chrome.com/docs/apps/reference/hid#type-HidConnectInfo)

#### Returns

- Promise\<[HidConnectInfo](https://developer.chrome.com/docs/apps/reference/hid#type-HidConnectInfo)\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### disconnect()

Promise

```typescript
chrome.hid.disconnect(
  connectionId: number,
  callback?: function,
): Promise<void>
```

Disconnect from a device. Invoking operations on a device after calling this is safe but has no effect.

#### Parameters

- connectionId number

  The `connectionId` returned by [`connect`](https://developer.chrome.com/docs/apps/reference/hid#method-connect).
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  () => void
  ```

  <br />

#### Returns

- Promise\<void\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### getDevices()

Promise

```typescript
chrome.hid.getDevices(
  options: GetDevicesOptions,
  callback?: function,
): Promise<https://developer.chrome.com/docs/apps/reference/hid#type-HidDeviceInfo[]>
```

Enumerate connected HID devices.

#### Parameters

- options [GetDevicesOptions](https://developer.chrome.com/docs/apps/reference/hid#type-GetDevicesOptions)

  The properties to search for on target devices.
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (devices: HidDeviceInfo[]) => void
  ```

  <br />

  - devices [HidDeviceInfo](https://developer.chrome.com/docs/apps/reference/hid#type-HidDeviceInfo)\[\]

#### Returns

- Promise\<[HidDeviceInfo](https://developer.chrome.com/docs/apps/reference/hid#type-HidDeviceInfo)\[\]\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### receive()

```typescript
chrome.hid.receive(
  connectionId: number,
  callback: function,
): void
```

Receive the next input report from the device.

#### Parameters

- connectionId number

  The `connectionId` returned by [`connect`](https://developer.chrome.com/docs/apps/reference/hid#method-connect).
- callback function


  The `callback` parameter looks like:

  ```typescript
  (reportId: number, data: ArrayBuffer) => void
  ```

  <br />

  - reportId number

    The report ID or `0` if none.
  - data ArrayBuffer

    The report data, the report ID prefix (if present) is removed.

### receiveFeatureReport()

Promise

```typescript
chrome.hid.receiveFeatureReport(
  connectionId: number,
  reportId: number,
  callback?: function,
): Promise<ArrayBuffer>
```

Request a feature report from the device.

#### Parameters

- connectionId number

  The `connectionId` returned by [`connect`](https://developer.chrome.com/docs/apps/reference/hid#method-connect).
- reportId number

  The report ID, or `0` if none.
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  (data: ArrayBuffer) => void
  ```

  <br />

  - data ArrayBuffer

    The report data, including a report ID prefix if one is sent by the device.

#### Returns

- Promise\<ArrayBuffer\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### send()

Promise

```typescript
chrome.hid.send(
  connectionId: number,
  reportId: number,
  data: ArrayBuffer,
  callback?: function,
): Promise<void>
```

Send an output report to the device.

*Note:* Do not include a report ID prefix in `data`. It will be added if necessary.

#### Parameters

- connectionId number

  The `connectionId` returned by [`connect`](https://developer.chrome.com/docs/apps/reference/hid#method-connect).
- reportId number

  The report ID to use, or `0` if none.
- data ArrayBuffer

  The report data.
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  () => void
  ```

  <br />

#### Returns

- Promise\<void\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

### sendFeatureReport()

Promise

```typescript
chrome.hid.sendFeatureReport(
  connectionId: number,
  reportId: number,
  data: ArrayBuffer,
  callback?: function,
): Promise<void>
```

Send a feature report to the device.

*Note:* Do not include a report ID prefix in `data`. It will be added if necessary.

#### Parameters

- connectionId number

  The `connectionId` returned by [`connect`](https://developer.chrome.com/docs/apps/reference/hid#method-connect).
- reportId number

  The report ID to use, or `0` if none.
- data ArrayBuffer

  The report data.
- callback function optional


  The `callback` parameter looks like:

  ```typescript
  () => void
  ```

  <br />

#### Returns

- Promise\<void\>
  Chrome 117+


  Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.

## Events

### onDeviceAdded

```typescript
chrome.hid.onDeviceAdded.addListener(
  callback: function,
)
```

Event generated when a device is added to the system. Events are only broadcast to apps and extensions that have permission to access the device. Permission may have been granted at install time or when the user accepted an optional permission (see [`permissions.request`](https://developer.chrome.com/docs/apps/permissions/#method-request)).

#### Parameters

- callback function


  The `callback` parameter looks like:

  ```typescript
  (device: HidDeviceInfo) => void
  ```

  <br />

  - device [HidDeviceInfo](https://developer.chrome.com/docs/apps/reference/hid#type-HidDeviceInfo)

### onDeviceRemoved

```typescript
chrome.hid.onDeviceRemoved.addListener(
  callback: function,
)
```

Event generated when a device is removed from the system. See [`onDeviceAdded`](https://developer.chrome.com/docs/apps/reference/hid#event-onDeviceAdded) for which events are delivered.

#### Parameters

- callback function


  The `callback` parameter looks like:

  ```typescript
  (deviceId: number) => void
  ```

  <br />

  - deviceId number

<br />