Copyright © 2024 the Contributors to the WebHID API Specification, published by the Web Platform Incubator Community Group under the W3C Community Contributor License Agreement (CLA). A human-readable summary is available.
This document describes an API for providing access to devices that support the Human Interface Device (HID) protocol.
This specification was published by the Web Platform Incubator Community Group. It is not a W3C Standard nor is it on the W3C Standards Track. Please note that under the W3C Community Contributor License Agreement (CLA) there is a limited opt-out and other conditions apply. Learn more about W3C Community and Business Groups.
GitHub Issues are preferred for discussion of this specification.
This section is non-normative.
A HID (Human Interface Device) is a type of device that takes input from or provides output to humans. It also refers to the HID protocol, a standard for bi-directional communication between a host and a device that is designed to simplify the installation procedure. The HID protocol was originally developed for USB devices but has since been implemented over many other protocols, including Bluetooth.
The web platform already supports input from many HID devices. Keyboards, pointing devices, and gamepads are all typically implemented using the HID protocol. However, this support relies on the operating system's HID drivers that transform the HID input into high-level input APIs. Devices that are not well supported by the host's HID driver are often inaccessible to web pages. Similarly, the outputs on most devices that are not supported by the host's HID driver are inaccessible.
See also the related Explainer document.
This section is non-normative.
The most common classes of HID input devices are already
well-supported on the web platform through existing high-level input
APIs. For instance, mouse input is accessible through
PointerEvent
and keyboard input is accessible through
KeyboardEvent
. Input from these devices is handled using the
host's native HID driver and typically does not require
device-specific drivers or configuration to work correctly. WebHID is
not intended for devices like these that are already well-supported
through high-level input APIs.
For some classes of HID devices, the web platform supports some features of the device but limits access to other features. For instance, [GAMEPAD] supports the input capabilities of most game controllers but does not support less common capabilities like LED indicators or audio. These features are often not well-supported by host APIs and adding support within the user agent can lead to significant complexity. WebHID would give applications an alternative when the functionality provided by the high-level API is incomplete.
Many HID devices are not supported through any web platform API. The HID specification describes a wide array of devices that could be supported through HID, including virtual reality controls, flight simulators, medical equipment, and more. WebHID would allow these devices to be used without requiring additional drivers or modification to the user agent.
HID is attractive for prototyping and hobbyist applications because it allows devices to use the host's generic HID driver instead of requiring a driver for each host where the device will be used. The simplified installation procedure also makes it easier for educators to deploy a device to a classroom of students without modifying the system configuration on each host. Providing access to HID devices through the web platform would further reduce installation requirements, particularly for devices that are currently only supported through host-specific applications.
This section is non-normative.
HID peripherals may expose powerful functionality that should not be made accessible to the page without explicit consent from the user. For instance, a HID peripheral may have sensors that allow it to collect information about its surroundings. A device may store private information that should not be revealed or overwritten. Many devices expose functionality that allow the device firmware to be upgraded. Operating systems typically do not restrict access to HID devices from applications, and this access can occasionally be abused to damage the device or corrupt the data stored on it.
In some cases, a device may expose functionality that should not be accessible at all from a web page. Specific devices may be blocked by recognizing the device by its vendor ID and product ID and hiding such devices during enumeration. The report descriptor allows a device to describe its own capabilities, and this information can be used to block classes of devices even when the vendor ID and product ID cannot be known in advance. This can be accomplished by inspecting the HID usage values assigned to collections within the report descriptor; for instance, access to keyboard-like devices can be denied by denying access to devices that include a top-level collection with the HID usage for a keyboard.
To mitigate abuse, a device will not be made available to the page until the user has granted explicit access. Access must first be requested by the page and will be granted once the user has selected the device from a chooser displaying all available devices. Once a page has been granted access, an indicator will be displayed to indicate the device is in use.
The HID protocol is extremely versatile, and a wide variety of devices have been designed that take advantage of this versatility. As a result, there are many possibilities for how access to a device could allow a malicious page to damage the device itself. It is relatively common for HID peripherals to allow firmware updates to be sent using custom HID reports. Device manufacturers must take care to design the firmware upgrade mechanism to verify that the firmware binary is authentic, and should also protect against downgrades that could reduce the security of a device. Untrusted upgrades could be used to add new capabilities to a device or cause it to masquerade as an entirely different type of device.
Some devices may be damaged when inputs are provided outside of the expected range. For instance, the rumble feature on a gamepad could become damaged if a page sends an invalid rumble command.
In general, these types of attacks are device-specific and cannot be mitigated at the API level.
If a malicious page gains access to a device, in some cases this access can be used to attack the host. A major concern is whether the device can be used to generate trusted input events. These events serve as a proxy for user intent and can be used to access more powerful web platform features.
Mice and keyboards are typically implemented as HID peripherals, and are also capable of generating trusted input. A HID keyboard or mouse may contain advanced features like programmable macros, which store a sequence of inputs and allow the sequence to be played back at a later time. Device manufacturers must take care to design such features in a way that would prevent a malicious app from reprogramming the device with an unexpected input sequence, and must also protect against triggering macro playback without the user's explicit consent.
To mitigate security and privacy risks, it is recommended that user agents implement a chooser-based flow for requesting device access. When a page requests access to a HID device, the user agent should display a dialog that informs the user that the page wants to access a device. The dialog should display a list of connected HID devices and ask the user to select a device that will be exposed to the page. To reduce the possibility of accidental clicks, the dialog should require two separate interactions: one interaction to select the device from the list and a second interaction to confirm the selection and dismiss the dialog.
WebIDL[Exposed=(DedicatedWorker,ServiceWorker,Window), SecureContext]
interface HID
: EventTarget {
attribute EventHandler onconnect
;
attribute EventHandler ondisconnect
;
Promise<sequence<HIDDevice
>> getDevices
();
[Exposed=Window] Promise<sequence<HIDDevice
>> requestDevice
(
HIDDeviceRequestOptions
options);
};
The user agent's implement may choose to conditionally expose
hid
attribute of the Navigator
when the relevant global object
of the Navigator
is ServiceWorkerGlobalScope
. For example,
in the Browser extension contexts of [browserext].
Instances of HID
are created with the internal slots described in
the following table:
Internal slot | Initial value | Description (non-normative) |
---|---|---|
[[devices]] | An empty ordered set |
An ordered set of HIDDevice instances representing the
HID interfaces currently available on the system
|
onconnect
attribute
onconnect
is an event handler IDL attribute for the
connect event type.
ondisconnect
attribute
ondisconnect
is an event handler IDL attribute for the
disconnect event type.
When a HID interface becomes available on the system, run the following steps:
A HID interface is a logical interface that can be used to communicate with a device over the HID protocol. Each HID interface has exactly one report descriptor that describes the set of reports supported by that interface. A single physical device may expose more than one HID interface. Devices with multiple HID interfaces run these steps once for each interface.
For example, USB devices are implemented as a collection of interfaces, each of which may specify an interface class. When a device has multiple USB interfaces that use the HID class, each interface is enumerated as a separate HID interface.
HIDDevice
.
[[vendorId]]
to the vendor ID of the
device that exposes the interface.
[[productId]]
to the product ID of
the device that exposes the interface.
[[productName]]
to the product name
of the device that exposes the interface.
[[collections]]
to the result of
parsing the Report descriptor.
Navigator
object's hid
getter if device's
relevant global object is a Window
object, otherwise be the
result of calling device's relevant global object's WorkerNavigator
object's hid
getter.
[[devices]]
.
requestDevice
()
, then queue a global task on the relevant global object of hid using the HID device task source to fire an event named connect
at hid
using HIDConnectionEvent
with its device
attribute initialized to device.
To parse the report descriptor, run the following steps:
The system will typically read the report descriptor byte sequence for each HID interface when a device is first connected and cache the values in the system registry. If the report descriptor is not available but the system provides information that can be used to reconstruct the layout of each report, the user agent may use an alternate algorithm instead of parsing the report descriptor.
The report descriptor format is described in [USBIF-HID-CLASS] section 6.2.2. The algorithm below is intended to implement the same parsing algorithm described in that section.
The report descriptor contains three classes of items. Main items are used to define and group data fields. Global items and Local items describe the data fields. Local items define characteristics that only apply to the next Main item, while Global items define characteristics that affect all subsequently defined Main items.
Each item has a item data field containing 0, 1, 2, or 4 bytes of data associated with the item and a bSize field that describes how many bytes are used to store the item data field. Each item also has a tag that identifies its type.
HIDCollectionInfo
.
unsigned long
.
unitSystem
"] to
"none
".
unitExponent
"] to 0.
unitFactorLengthExponent
"] to
0.
unitFactorMassExponent
"] to 0.
unitFactorTimeExponent
"] to 0.
unitFactorTemperatureExponent
"]
to 0.
unitFactorCurrentExponent
"] to
0.
unitFactorLuminousIntensityExponent
"]
to 0.
logicalMinimum
"] to 0.
logicalMaximum
"] to 0.
physicalMinimum
"] to 0.
physicalMaximum
"] to 0.
Main items are described in [USBIF-HID-CLASS] sections 6.2.2.4 through 6.2.2.6. An item with the Input tag, Output tag, or Feature tag defines a field within an input, output, or feature report. The item data field of a Main item with an Input tag, Output tag, or Feature tag is a bit field containing several boolean parameters describing the data field. An item with the Collection tag defines a new collection nested within the current collection, or a new top-level collection if there is no current collection. The item data field of a Main item with a Collection tag contains the collection type. An item with the End Collection tag closes the current collection.
reportId
"].
inputReports
"]
if item has the Input tag,
outputReports
"]
if item has the Output tag, or
featureReports
"]
if item has the Feature tag.
If reports contains an item with its
reportId
attribute equal to
reportId, then let report be that item.
Otherwise:
HIDReportInfo
dictionary.
reportId
"] to
reportId.
items
"] to an
empty sequence of HIDReportItem
.
items
"].
HIDCollectionInfo
dictionary.
usagePage
"] to
globalState["usagePage
"].
usage
"] to
usage.
type
"] to the
value representing the collection's type.
children
"] to
an empty sequence of HIDCollectionInfo
.
inputReports
"]
to an empty sequence of HIDReportInfo
.
outputReports
"]
to an empty sequence of HIDReportInfo
.
featureReports
"] to an
empty sequence of HIDReportInfo
.
If ancestors is empty, append collection to collections.
Otherwise:
unsigned
long
.
Global items are described in section 6.2.2.7. An item with the Usage Page tag, Logical Minimum tag, Logical Maximum tag, Physical Minimum tag, Physical Maximum tag, Unit Exponent tag, Unit tag, Report Size tag, Report ID tag, or Report Count tag modifies the respective field of the global item state table. An item with the Push tag pushes a copy of the current global item state table onto the item state stack. An item with the Pop tag replaces the global item state table with the top of the item state stack. The global Report ID value is not affected when manipulating the item state stack.
unsigned long
.
usagePage
"] to
value.
logicalMinimum
"] to
value.
logicalMaximum
"] to
value.
physicalMinimum
"] to
value.
physicalMaximum
"] to
value.
reportSize
"] to value.
reportId
"] to value.
reportCount
"] to value.
unitSystem
"] to
"none
"
unitSystem
"] to
"si-linear
"
unitSystem
"] to
"si-rotation
"
unitSystem
"] to
"english-linear
"
unitSystem
"] to
"english-rotation
"
unitSystem
"] to
"vendor-defined
"
unitSystem
"] to
"reserved
"
unitFactorLengthExponent
"]
to nibbles[1].
unitFactorMassExponent
"]
to nibbles[2].
unitFactorTimeExponent
"]
to nibbles[3].
unitFactorTemperatureExponent
"]
to nibbles[4].
unitFactorCurrentExponent
"]
to nibbles[5].
unitFactorLuminousIntensityExponent
"]
to nibbles[6].
unitExponent
"] to the
result of interpreting the lowest 4 bits of the item data field as a signed two's complement integer.
Local items are described in section 6.2.2.8. An item with the Usage tag, Usage Minimum tag, Usage Maximum tag, String Index tag, String Minimum tag, or String Maximum tag modifies the respective field of the local item state table. The local item state is cleared after each Main item.
unsigned long
.
usageMinimum
"] to value.
usageMaximum
"] to value.
"stringMinimum"
] to value.
"stringMaximum"
] to value.
To create a HID report item with item, localState, globalState, usages, and stringIndices, run the following steps:
HIDReportItem
dictionary.
unsigned long
.
boolean
values representing each
of the bits of value, starting from the low-order bits.
isConstant
"] to bitfield[0].
isArray
"] to !bitfield[1].
isAbsolute
"] to !bitfield[2].
wrap
"] to bitfield[3].
isLinear
"] to !bitfield[4].
hasPreferredState
"] to
bitfield[5].
hasNull
"] to bitfield[6].
isVolatile
"] to bitfield[7].
isBufferedBytes
"] to
bitfield[8].
usages
"] to usages.
reportSize
"] to
globalState["reportSize
"].
reportCount
"] to
globalState["reportCount
"].
unitExponent
"] to
globalState["unitExponent
"].
unitSystem
"] to
globalState["unitSystem
"].
unitFactorLengthExponent
"] to
globalState["unitFactorLengthExponent
"].
unitFactorMassExponent
"] to
globalState["unitFactorMassExponent
"].
unitFactorTimeExponent
"] to
globalState["unitFactorTimeExponent
"].
unitFactorTemperatureExponent
"]
to globalState["unitFactorTemperatureExponent
"].
unitFactorCurrentExponent
"] to
globalState["unitFactorCurrentExponent
"].
unitFactorLuminousIntensityExponent
"]
to
globalState["unitFactorLuminousIntensityExponent
"].
logicalMinimum
"] to
globalState["logicalMinimum
"].
logicalMaximum
"] to
globalState["logicalMaximum
"].
physicalMinimum
"] to
globalState["physicalMinimum
"].
physicalMaximum
"] to
globalState["physicalMaximum
"].
If "usageMinimum
" is in localState, then set
reportItem["usageMinimum
"] to
localState["usageMinimum
"].
If "usageMaximum
" is in localState, then set
reportItem["usageMaximum
"] to
localState["usageMaximum
"].
isRange
"] to true
if
reportItem["usageMinimum
"] is less than
reportItem["usageMaximum
"], or false
otherwise.
"stringMinimum"
is in localState and "stringMaximum"
is in
localState:
When a HID interface becomes unavailable on the system, run the following steps:
HIDDevice
in
hid.[[devices]]
representing the interface.
Navigator
object's hid
getter if device's
relevant global object is a Window
object, otherwise be the
result of calling device's relevant global object's WorkerNavigator
object's hid
getter.
[[devices]]
.
requestDevice
()
, then queue a global task on the relevant global object of hid using the HID device task source to fire an event named disconnect
at hid
using HIDConnectionEvent
with its device
attribute initialized to device.
The getDevices
()
method steps are:
null
.DedicatedWorkerGlobalScope
or window
object, set document to this's
relevant global object's associated Document.
ServiceWorkerGlobalScope
object and the associated service worker client is
window client, set document to the
associated Document of the associated service worker client's
global object.
null
or document is not allowed to use
the policy-controlled feature named "hid"
, reject
promise with a "SecurityError
" DOMException
and return promise.
HIDDevice
.
[[devices]]
:
requestDevice
()
and
device.[[state]]
is not "forgotten"
, then
append device to devices.
The requestDevice
()
permission dialog presents a list of
connected devices and asks the user to select one.
If a device has multiple HID interfaces, the dialog MAY present only a single item that represents all the interfaces. When the user selects an item that represents multiple HID interfaces, the user agent MUST grant access to all the HID interfaces exposed by the device.
The requestDevice
()
method steps are:
"hid"
, reject promise with a
"SecurityError
" DOMException
and return promise.
window
,
reject promise with a "NotSupportedError
"
DOMException
and return promise.
SecurityError
" DOMException
and return promise.
filters
"] is present,
then run the following steps for each
filter of
options["filters
"]:
TypeError
and return promise.
exclusionFilters
"] is
present, then run the following steps:
exclusionFilters
"]
is empty, then reject promise with a TypeError
and
return promise.
exclusionFilters
"]:
TypeError
and return
promise.
[[devices]]
:
filters
"] and device
does not match any filter in
options["exclusionFilters
"],
then append device to availableDevices.
HIDDevice
.
[[devices]]
:
[[state]]
to
"closed"
and append device to devices.
WebIDLdictionary HIDDeviceRequestOptions
{
required sequence<HIDDeviceFilter
> filters
;
sequence<HIDDeviceFilter
> exclusionFilters
;
};
filters
member
exclusionFilters
member
WebIDLdictionary HIDDeviceFilter
{
unsigned long vendorId
;
unsigned short productId
;
unsigned short usagePage
;
unsigned short usage
;
};
vendorId
member
productId
member
vendorId
member is not present, productId
is ignored.
usagePage
member
usage
member
usagePage
member is not present,
usage
is ignored.
Device filters are used to narrow the list of devices presented
to the user in the chooser dialog created by
requestDevice
()
. When no filters are provided, all
connected devices matching no exclusion filters are included.
When one or more filters are provided, a device is included if
any filter matches and no exclusion filters matches.
All HIDDeviceFilter
members are optional. Each member
specifies a rule. To match a HIDDeviceFilter
, every rule must
be satisfied. An empty HIDDeviceFilter
matches any device.
Device ID rules are used to select devices by their vendor ID
and product ID. This is useful when an application is only
designed to work with a specific device, or otherwise relies on
vendor-specific functionality. Including a
vendorId
rule causes the filter to only match
devices with the specified vendor ID. If a
productId
rule is also included, the filter
will only match devices with the specified vendor ID and
product ID. productId
is ignored if it is
specified without a vendorId
rule.
Usage rules are used to select devices by the HID usages
assigned to the top-level collections of the device. This is
useful when an application is designed to work with a standard
class of device. To match a device, at least one of the device's
collections must match every usage rule. Including a
usagePage
rule causes the filter to only
match if the device contains a collection with the specified
usage page. If a usage
rule is also
included, the filter will only match devices with the specified
usage page and usage ID. usage
is
ignored if it is specified without a
usagePage
rule.
Device ID rules and usage rules may be combined. For instance, an application may want to match devices from a particular vendor, but only devices that implement a specific device class.
The exclusionFilters
option allows an
application to exclude some devices presented to the user from
the chooser dialog created by requestDevice
()
that are
known to not work as expected, even though they implement a
specific device class for instance.
A HIDDeviceFilter
filter is a valid
filter if these steps return true
:
false
.
productId
"] is present and
filter["vendorId
"] is not present, then
return false
.
usage
"] is present and
filter["usagePage
"] is not present, then
return false
.
true
.
A HIDDevice
device matches any filter in a sequence
filters of HIDDeviceFilter
if
these steps return true
:
true
.
true
.
false
.
A HIDDeviceFilter
filter matches the
device IDs of device if these steps return
true
:
vendorId
" is in filter:
true
.
A HIDDeviceFilter
filter matches any
collection of device if these steps return
true
:
collections
:
true
.
false
.
A HIDDeviceFilter
filter matches the
collection collection if these steps
return true
:
WebIDL[Exposed=(DedicatedWorker,ServiceWorker,Window), SecureContext]
interface HIDDevice
: EventTarget {
attribute EventHandler oninputreport
;
readonly attribute boolean opened
;
readonly attribute unsigned short vendorId
;
readonly attribute unsigned short productId
;
readonly attribute DOMString productName
;
readonly attribute FrozenArray<HIDCollectionInfo
> collections
;
Promise<undefined> open
();
Promise<undefined> close
();
Promise<undefined> forget
();
Promise<undefined> sendReport
([EnforceRange] octet reportId, BufferSource data);
Promise<undefined> sendFeatureReport
(
[EnforceRange] octet reportId,
BufferSource data);
Promise<DataView> receiveFeatureReport
([EnforceRange] octet reportId);
};
Methods on this interface typically complete asynchronously, queuing work on the HID device task source.
Instances of HIDDevice
are created with the internal slots
described in the following table:
Internal slot | Initial value | Description (non-normative) |
---|---|---|
[[state]] |
"closed"
|
Tracks the active state of the HIDDevice
|
[[vendorId]] | 0 | The vendor ID of the device |
[[productId]] | 0 | The product ID of the device |
[[productName]] |
""
|
The product name of the device |
[[collections]] |
An empty sequence of HIDCollectionInfo
|
The top-level collections created by parsing the report descriptor |
[[pendingSendReportPromises]] | An empty list |
Pending sendReport () Promise s
|
[[pendingSendFeatureReportPromises]] | An empty list |
Pending sendFeatureReport () Promise s
|
[[pendingReceiveFeatureReportPromises]] | An empty list |
Pending receiveFeatureReport () Promise s
|
oninputreport
attribute
oninputreport
is an event handler IDL attribute for
the inputreport event type.
opened
attribute
A flag indicating that the HIDDevice
is ready to transfer data.
The opened
getter steps are:
vendorId
attribute
A vendor ID is an unsigned short
value assigned by a
vendor ID source that identifies the manufacturer of a device.
The vendorId
attribute is the vendor ID of the
device. If the device has no vendor ID or the vendor ID
cannot be accessed, the attribute MUST be 0.
The vendorId
getter steps are:
[[vendorId]]
.
productId
attribute
A product ID is an unsigned short
value assigned by
the manufacturer of the device that identifies the product.
The productId
attribute is the product ID of the
device. If the device has no product ID or the product ID
cannot be accessed, the attribute MUST be 0.
The productId
getter steps are:
[[productId]]
.
productName
attribute
A string identifying the product.
For USB HID devices, the product name SHOULD contain the
value of the string descriptor at the index iProduct
specified in
the Device Descriptor. For Bluetooth HID devices, the product name SHOULD contain the value of the Device Name characteristic.
If the device has no product name or the product name is
empty or cannot be accessed, the attribute MUST return an empty
string.
The productName
string SHOULD NOT contain any
identifiers like a serial number or Bluetooth device address that
could be used to uniquely identify the device.
The productName
getter steps are:
[[productName]]
.
collections
attribute
A sequence of HIDCollectionInfo
representing the
top-level collections in the report descriptor.
The collections
getter steps are:
[[collections]]
.
When an input report is received from a device, run the following steps:
DataView
created over the byte sequence representing the input report. If the HID interface
uses report IDs, the byte sequence MUST NOT include the report
ID byte.
inputreport
at device using HIDInputReportEvent
with
its device
attribute initialized to device,
its reportId
attribute initialized to
reportId, and its data
attribute initialized
to data.
The open
()
method steps are:
[[state]]
is not "closed"
, then
reject promise with a "InvalidStateError
" DOMException
and return promise.
[[state]]
to "opening"
.
NetworkError
"
DOMException
and abort these steps.
[[state]]
to "opened"
.
undefined
.
The close
()
method steps are:
[[state]]
is either "forgotten"
or
"forgetting"
, then reject promise with a
"InvalidStateError
" DOMException
and return promise.
[[state]]
to "closing"
.
[[pendingSendReportPromises]]
:
AbortError
"
DOMException
.
[[pendingSendReportPromises]]
.
[[pendingSendFeatureReportPromises]]
:
AbortError
"
DOMException
.
[[pendingSendFeatureReportPromises]]
.
[[pendingReceiveFeatureReportPromises]]
:
AbortError
"
DOMException
.
[[pendingReceiveFeatureReportPromises]]
.
[[state]]
to "closed"
.
undefined
.
The user agent MAY decide to combine permissions across APIs, for instance tracking WebHID + WebUSB device access under a unified low-level device access permission. This is why this method may also revoke additional (unspecified yet) permissions in the future.
The forget
()
method steps are:
[[devices]]
:
[[state]]
to "forgetting"
.
[[pendingSendReportPromises]]
:
AbortError
"
DOMException
.
[[pendingSendReportPromises]]
.
[[pendingSendFeatureReportPromises]]
:
AbortError
"
DOMException
.
[[pendingSendFeatureReportPromises]]
.
[[pendingReceiveFeatureReportPromises]]
:
AbortError
"
DOMException
.
[[pendingReceiveFeatureReportPromises]]
.
[[state]]
to "forgotten"
.
undefined
.
The sendReport
()
method is used to send an output
report with the specified reportId and data.
If the HID interface does not use report IDs, pass 0
instead of the report ID.
For HID interfaces that use report IDs, the report ID value 0 is reserved and should not be used.
The sendReport
()
method steps are:
[[state]]
is not "opened"
, then
reject promise with a "InvalidStateError
" DOMException
and return promise.
TypeError
" DOMException
and return promise.
[[pendingSendReportPromises]]
.
NotAllowedError
" DOMException
and abort these steps.
NetworkError
"
DOMException
and abort these steps.
undefined
.
The sendFeatureReport
()
method is used to send a
feature report with the specified reportId and
data. If the HID interface does not use report IDs, pass 0 instead of the report ID.
For HID interfaces that use report IDs, the report ID value 0 is reserved and should not be used.
The sendFeatureReport
()
method steps are:
[[state]]
is not "opened"
, then
reject promise with a "InvalidStateError
" DOMException
and return promise.
TypeError
" DOMException
and return promise.
[[pendingSendFeatureReportPromises]]
.
NotAllowedError
" DOMException
and abort these steps.
NetworkError
"
DOMException
and abort these steps.
undefined
.
The receiveFeatureReport
()
method is used to request
a feature report with the specified reportId. If the HID interface does not use report IDs, pass 0 instead of the
report ID.
For HID interfaces that use report IDs, the report ID value 0 is reserved and should not be used.
The receiveFeatureReport
()
method steps are:
[[state]]
is not "opened"
, then
reject promise with a "InvalidStateError
" DOMException
and return promise.
TypeError
" DOMException
and return promise.
[[pendingReceiveFeatureReportPromises]]
.
NotAllowedError
" DOMException
and abort these steps.
DataView
created over the byte sequence representing the result of invoking the operating
system to read a feature report with the specified
reportId.
NetworkError
" DOMException
and abort these steps.
WebIDL[Exposed=(DedicatedWorker,ServiceWorker,Window), SecureContext]
interface HIDConnectionEvent
: Event {
constructor
(DOMString type, HIDConnectionEventInit
eventInitDict);
[SameObject] readonly attribute HIDDevice
device
;
};
device
attribute
HIDDevice
instance that represents the connected or
disconnected device.
WebIDLdictionary HIDConnectionEventInit
: EventInit {
required HIDDevice
device
;
};
device
member
WebIDL[Exposed=(DedicatedWorker,ServiceWorker,Window), SecureContext]
interface HIDInputReportEvent
: Event {
constructor
(DOMString type, HIDInputReportEventInit
eventInitDict);
[SameObject] readonly attribute HIDDevice
device
;
readonly attribute octet reportId
;
readonly attribute DataView data
;
};
device
attribute
HIDDevice
instance that represents the HID interface that
sent the input report.
reportId
attribute
data
attribute
DataView
containing the data from the input report, excluding
the reportId
byte if the HID interface
uses report IDs.
WebIDLdictionary HIDInputReportEventInit
: EventInit {
required HIDDevice
device
;
required octet reportId
;
required DataView data
;
};
device
member
reportId
member
data
member
WebIDLdictionary HIDCollectionInfo
{
unsigned short usagePage
;
unsigned short usage
;
octet type
;
sequence<HIDCollectionInfo
> children
;
sequence<HIDReportInfo
> inputReports
;
sequence<HIDReportInfo
> outputReports
;
sequence<HIDReportInfo
> featureReports
;
};
When a device is first connected to the system, the system MUST retrieve the report descriptor for each HID interface exposed by the device. The Report descriptor is a byte sequence that can be expanded into a hierarchical data structure describing the layout of each report supported by the device. The elements of this data structure are called items. Groups of items that share a relationship are called collections.
A HIDCollectionInfo
object represents a single collection within
the report descriptor. When a collection contains nested
collections, the nested collections are included as elements of
children
.
The inputReports
,
outputReports
, and
featureReports
attributes contain sequences
of HIDReportInfo
that give information about each report described
within this collection. For a top-level collection, the
HIDReportInfo
represents a flattened view of all items that compose
the report. The flattened view interleaves items contained in nested
collections with items contained within the top-level collection.
For a nested collection, the HIDReportInfo
includes only the items
contained within the collection and its nested collections.
usagePage
member
The usage page component of the HID usage associated with this collection.
HID usages are constants that can be interpreted by an
application to identify the purpose and meaning of an item or
collection. A HID usage is an unsigned long
value composed of
an unsigned short
usage page in the high order bits
and an unsigned short
usage ID in the low order bits.
Standard HID usage values are described in [USBIF-HID-CLASS]
and other documents published by the USB Implementers Forum.
The HID usages of the top-level collections exposed by the device is used to identify the general device type.
usage
member
The usage ID component of the HID usage associated with this collection.
A usage ID is used to select an individual HID usage on a usage page. By convention, usage IDs 0x01 through 0x1F are reserved for top-level collections.
type
member
A value representing the collection type.
Collection type | Value |
---|---|
Physical | 0x00 |
Application | 0x01 |
Logical | 0x02 |
Report | 0x03 |
Named Array | 0x04 |
Usage Switch | 0x05 |
Usage Modified | 0x06 |
Reserved for future use | 0x07 to 0x7F |
Vendor-defined | 0x80 to 0xFF |
Each collection type describes a different type of relationship among the grouped items. Refer to [USBIF-HID-CLASS] section 6.2.2.6 for more information about collection types.
children
member
HIDCollectionInfo
representing the collections
nested within this collection.
inputReports
member
HIDReportInfo
representing the input reports
described within this collection.
outputReports
member
HIDReportInfo
representing the output reports
described within this collection.
featureReports
member
HIDReportInfo
representing the feature reports
described within this collection.
WebIDLdictionary HIDReportInfo
{
octet reportId
;
sequence<HIDReportItem
> items
;
};
A HIDReportInfo
represents one input, output, or feature report
within the report descriptor.
reportId
member
reportId
member is the prefix
for this report if the interface uses report IDs, or 0 otherwise.
items
member
HIDReportItem
representing the fields of this
report.
WebIDLdictionary HIDReportItem
{
boolean isAbsolute
;
boolean isArray
;
boolean isBufferedBytes
;
boolean isConstant
;
boolean isLinear
;
boolean isRange
;
boolean isVolatile
;
boolean hasNull
;
boolean hasPreferredState
;
boolean wrap
;
sequence<unsigned long> usages
;
unsigned long usageMinimum
;
unsigned long usageMaximum
;
unsigned short reportSize
;
unsigned short reportCount
;
byte unitExponent
;
HIDUnitSystem
unitSystem
;
byte unitFactorLengthExponent
;
byte unitFactorMassExponent
;
byte unitFactorTimeExponent
;
byte unitFactorTemperatureExponent
;
byte unitFactorCurrentExponent
;
byte unitFactorLuminousIntensityExponent
;
long logicalMinimum
;
long logicalMaximum
;
long physicalMinimum
;
long physicalMaximum
;
sequence<DOMString> strings
;
};
isAbsolute
member
true
if the data is absolute (based on a fixed origin), or false
if the data is relative (indicating the change in value from the last
report).
isArray
member
true
if the item creates array data fields in reports where each
data field contains an index corresponding to a pressed button or
key, or false
if the item creates variable data fields in reports
where each data field contains a value.
isBufferedBytes
member
true
if the item emits a fixed-sized stream of bytes, or false
if
the item is a numeric quantity.
isConstant
member
true
if the item is a static read-only field and cannot be
modified, or false
if the item defines report fields that contain
modifiable device data.
isLinear
member
true
if the item represents a linear relationship between what is
measured and what is reported, or false
if the data has been
processed in some way.
isRange
member
true
if the item assigns usages from a HID usage range defined
by usageMinimum
and usageMaximum
,
or false
if the item has a sequence of HID usage values in
usages
.
isVolatile
member
true
if the item value can change without host interaction, or
false
if the item value should only be changed by the host.
Only used for Feature and Output items.
hasNull
member
true
if the item has a null state in which it is not sending
meaningful data, or false
if it does not have a null state. When in
a null state, the item will report a value outside of the specified
logicalMinimum
and
logicalMaximum
.
hasPreferredState
member
true
if the item has a preferred state to which it will return when
the user is not physically interacting with the control, or false
if the item does not have a preferred state.
wrap
member
true
if the item value rolls over when reaching either the extreme
high or low value, or false
if the item value does not roll over.
usages
member
If isRange
is true
or this item has no
associated HID usage values, then usages
MUST
be undefined.
If isRange
is false
then
usages
is a sequence of HID usage values
associated with this item.
usageMinimum
member
If isRange
is true
then
usageMinimum
contains the minimum HID usage
value in the usage range associated with this item.
If isRange
is false
then
usageMinimum
MUST be undefined.
usageMaximum
member
If isRange
is true
then
usageMaximum
contains the maximum HID usage
value in the usage range associated with this item.
If isRange
is false
then
usageMaximum
MUST be undefined.
reportSize
member
reportSize
MUST be greater than 0.
reportCount
member
reportCount
MUST be greater than 0.
unitExponent
member
unitSystem
member
HIDUnitSystem
enum value specifying the unit system for the
unit definition, or "none
" if the item has no unit
definition.
unitFactorLengthExponent
member
unitFactorMassExponent
member
unitFactorTimeExponent
member
unitFactorTemperatureExponent
member
unitFactorCurrentExponent
member
unitFactorLuminousIntensityExponent
member
logicalMinimum
member
logicalMaximum
member
physicalMinimum
member
logicalMinimum
with units applied to
it.
physicalMaximum
member
logicalMaximum
with units applied to
it.
strings
member
[USBIF-HID-CLASS] section 6.2.2.7 defines four standard unit systems: SI Linear, SI Rotation, English Linear, and English Rotation. Each item uses one of these four unit systems, a vendor-defined unit system, or no unit system.
WebIDLenum HIDUnitSystem
{
"none
", "si-linear
", "si-rotation
", "english-linear
",
"english-rotation
", "vendor-defined
", "reserved
"
};
"none"
"si-linear"
"si-rotation"
"english-linear"
"english-rotation"
"vendor-defined"
"reserved"
This specification relies on a blocklist file in the https://github.com/WICG/webhid repository to restrict the set of HID devices a website can access.
The result of parsing the blocklist at a URL url is a sequence of dictionary objects produced by fetching url and parsing its contents as JSON.
The HID blocklist is the result of parsing the blocklist at https://github.com/WICG/webhid/blob/main/blocklist.txt
A report is a blocked report if the following steps return
true
:
true
.
false
.
A report is blocked by a blocklist rule rule if the
following steps return true
:
"input"
if the report is an input report,
"output"
if the report is an output report, or "feature"
if the
report is a feature report.
"vendor"
and rule["vendor"
] is not
device.vendorId
, return false
.
"product"
and rule["product"
] is not
device.productId
, return false
.
"reportId"
and rule["reportId"
] is not
reportId, return false
.
"reportType"
and rule["reportType"
] is not
reportType, return false
.
"usagePage"
and rule["usagePage"
] is not
collection["usagePage
"], return false
.
"usage"
and rule.["usage"
] is not
collection["usage
"], return false
.
true
.
This specification defines a feature that controls whether the
hid
attribute is exposed on the Navigator
object.
The feature name for this feature is "hid"
.
The default allowlist for this feature
is 'self'
.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MAY, MUST, MUST NOT, SHOULD, and SHOULD NOT in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in: