chrome.hid
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 and executing the function's regular callback. The
callback's regular parameters will be undefined in this case.
|
Availability: |
Since Chrome 38.
|
Permissions: |
"hid"
|
Summary
Types | |
---|---|
HidDeviceInfo | |
DeviceFilter | |
Methods | |
getDevices −
chrome.hid.getDevices(object options, function callback)
| |
getUserSelectedDevices −
chrome.hid.getUserSelectedDevices(object options, function callback)
| |
connect −
chrome.hid.connect(integer deviceId, function callback)
| |
disconnect −
chrome.hid.disconnect(integer connectionId, function callback)
| |
receive −
chrome.hid.receive(integer connectionId, function callback)
| |
send −
chrome.hid.send(integer connectionId, integer reportId, ArrayBuffer data, function callback)
| |
receiveFeatureReport −
chrome.hid.receiveFeatureReport(integer connectionId, integer reportId, function callback)
| |
sendFeatureReport −
chrome.hid.sendFeatureReport(integer connectionId, integer reportId, ArrayBuffer data, function callback)
| |
Events | |
onDeviceAdded | |
onDeviceRemoved |
Types
HidDeviceInfo
properties | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
integer | deviceId |
Opaque device ID. |
|||||||||
integer | vendorId |
Vendor ID. |
|||||||||
integer | productId |
Product ID. |
|||||||||
string | productName |
Since Chrome 46. The product name read from the device, if available. |
|||||||||
string | serialNumber |
Since Chrome 46. The serial number read from the device, if available. |
|||||||||
array of object | collections |
Top-level collections from this device's report descriptors. Properties of each object
|
|||||||||
integer | maxInputReportSize |
Top-level collection's maximum input report size. |
|||||||||
integer | maxOutputReportSize |
Top-level collection's maximum output report size. |
|||||||||
integer | maxFeatureReportSize |
Top-level collection's maximum feature report size. |
|||||||||
ArrayBuffer | reportDescriptor |
Since Chrome 42. Raw device report descriptor (not available on Windows). |
DeviceFilter
Since Chrome 39.
properties | ||
---|---|---|
integer | (optional) vendorId |
Device vendor ID. |
integer | (optional) productId |
Device product ID, only checked only if the vendor ID matches. |
integer | (optional) usagePage |
HID usage page identifier. |
integer | (optional) usage |
HID usage identifier, checked only if the HID usage page matches. |
Methods
getDevices
chrome.hid.getDevices(object options, function callback)
Enumerate connected HID devices.
Parameters | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
object | options |
The properties to search for on target devices.
|
|||||||||
function | callback |
The callback parameter should be a function that looks like this: function(array of HidDeviceInfo devices) {...};
|
getUserSelectedDevices
chrome.hid.getUserSelectedDevices(object options, function callback)
Dev channel only. Learn more.
Presents a device picker to the user and returns HidDeviceInfo objects for the devices selected. If the user cancels the picker devices will be empty. A user gesture is required for the dialog to display. Without a user gesture, the callback will run as though the user cancelled. If multiple filters are provided devices matching any filter will be displayed.
Parameters | ||||||||
---|---|---|---|---|---|---|---|---|
object | (optional) options |
Since Chrome 45. Configuration of the device picker dialog box.
|
||||||
function | callback |
Invoked with a list of chosen Devices. The callback parameter should be a function that looks like this: function(array of HidDeviceInfo devices) {...};
|
connect
chrome.hid.connect(integer deviceId, function callback)
Open a connection to an HID device for communication.
Parameters | ||||||||
---|---|---|---|---|---|---|---|---|
integer | deviceId |
The HidDeviceInfo.deviceId of the device to open. |
||||||
function | callback |
The callback parameter should be a function that looks like this: function(object connection) {...};
|
disconnect
chrome.hid.disconnect(integer connectionId, function callback)
Disconnect from a device. Invoking operations on a device after calling this is safe but has no effect.
Parameters | ||
---|---|---|
integer | connectionId |
The |
function | (optional) callback |
If you specify the callback parameter, it should be a function that looks like this: function() {...};
|
receive
chrome.hid.receive(integer connectionId, function callback)
Receive the next input report from the device.
Parameters | ||||||||
---|---|---|---|---|---|---|---|---|
integer | connectionId |
The |
||||||
function | callback |
The callback parameter should be a function that looks like this: function(integer reportId, ArrayBuffer data) {...};
|
send
chrome.hid.send(integer connectionId, integer reportId, ArrayBuffer data, function callback)
Send an output report to the device.
Note: Do not include a report ID prefix in data
. It will be added if necessary.
Parameters | ||
---|---|---|
integer | connectionId |
The |
integer | reportId |
The report ID to use, or |
ArrayBuffer | data |
The report data. |
function | callback |
The callback parameter should be a function that looks like this: function() {...};
|
receiveFeatureReport
chrome.hid.receiveFeatureReport(integer connectionId, integer reportId, function callback)
Request a feature report from the device.
Parameters | |||||
---|---|---|---|---|---|
integer | connectionId |
The |
|||
integer | reportId |
The report ID, or |
|||
function | callback |
The callback parameter should be a function that looks like this: function(ArrayBuffer data) {...};
|
sendFeatureReport
chrome.hid.sendFeatureReport(integer connectionId, integer reportId, ArrayBuffer data, function callback)
Send a feature report to the device.
Note: Do not include a report ID prefix in data
. It will be added if necessary.
Parameters | ||
---|---|---|
integer | connectionId |
The |
integer | reportId |
The report ID to use, or |
ArrayBuffer | data |
The report data. |
function | callback |
The callback parameter should be a function that looks like this: function() {...};
|
Events
onDeviceAdded
Since Chrome 41.
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).
addListener
chrome.hid.onDeviceAdded.addListener(function callback)
Parameters | |||||
---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function( HidDeviceInfo device) {...};
|
onDeviceRemoved
Since Chrome 41.
Event generated when a device is removed from the system. See onDeviceAdded for which events are delivered.
addListener
chrome.hid.onDeviceRemoved.addListener(function callback)
Parameters | |||||
---|---|---|---|---|---|
function | callback |
The callback parameter should be a function that looks like this: function(integer deviceId) {...};
|