Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebHID API available in workers #36060

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion files/en-us/web/api/hid/connect_event/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HID.connect_event
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`connect`** event of the {{domxref("HID")}} interface fires when the user agent connects to a HID device.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hid/disconnect_event/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HID.disconnect_event
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`disconnect`** event of the {{domxref("HID")}} interface fires when the user agent disconnects a HID device.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hid/getdevices/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HID.getDevices
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`getDevices()`** method of the {{domxref("HID")}} interface gets a list of the connected HID devices that the user has previously been granted access to in response to a {{domxref("HID.requestDevice","requestDevice()")}} call.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hid/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ status:
browser-compat: api.HID
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`HID`** interface provides methods for connecting to _HID devices_, listing attached HID devices and event handlers for connected HID devices.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hid/requestdevice/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HID.requestDevice
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requestDevice() is not available in workers as it triggers a visible user prompt

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've removed it from this page in the next commit.


The **`requestDevice()`** method of the {{domxref("HID")}} interface requests access to a HID device.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hidconnectionevent/device/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDConnectionEvent.device
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`device`** read-only property of the {{domxref("HIDConnectionEvent")}} interface returns the {{domxref("HIDDevice")}} associated with this connection event.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDConnectionEvent.HIDConnectionEvent
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`HIDConnectionEvent()`** constructor creates a new {{domxref("HIDConnectionEvent")}} object. Typically this constructor is not used as events are created when a device's connection state changes.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hidconnectionevent/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ status:
browser-compat: api.HIDConnectionEvent
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`HIDConnectionEvent`** interface of the [WebHID API](/en-US/docs/Web/API/WebHID_API) represents HID connection events, and is the event type passed to {{domxref("HID/connect_event", "connect")}} and {{domxref("HID/disconnect_event", "disconnect")}} event handlers when a device's connection state changes.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/close/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.close
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`close()`** method of the {{domxref("HIDDevice")}} interface closes the connection to the HID device.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/collections/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.collections
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`collections`** read-only property of the {{domxref("HIDDevice")}} interface returns an array of report formats

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/forget/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.forget
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`forget()`** method of the {{domxref("HIDDevice")}} interface closes the connection to the HID device and forgets the device.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ status:
browser-compat: api.HIDDevice
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`HIDDevice`** interface of the [WebHID API](/en-US/docs/Web/API/WebHID_API) represents a HID Device. It provides properties for accessing information about the device, methods for opening and closing the connection, and the sending and receiving of reports.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/inputreport_event/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.inputreport_event
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`inputreport`** event of the {{domxref("HIDDevice")}} interface fires when a new report is received from the HID device.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/open/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.open
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`open()`** method of the {{domxref("HIDDevice")}} interface requests that the operating system opens the HID device.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/opened/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.opened
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`opened`** read-only property of the {{domxref("HIDDevice")}} interface returns true if the connection to the {{domxref("HIDDevice")}} is open and ready to transfer data.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/productid/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.productId
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`productId`** read-only property of the {{domxref("HIDDevice")}} interface returns the product ID of the connected HID device.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/productname/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.productName
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`productName`** read-only property of the {{domxref("HIDDevice")}} interface returns the product name of the connected HID device.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.receiveFeatureReport
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`receiveFeatureReport()`** method of the {{domxref("HIDDevice")}} interface receives a feature report from the HID device. Feature reports are a way for HID devices and applications to exchange non-standardized HID data.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/sendfeaturereport/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.sendFeatureReport
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`sendFeatureReport()`** method of the {{domxref("HIDDevice")}} interface sends a feature report to the HID device. Feature reports are a way for HID devices and applications to exchange non-standardized HID data.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/sendreport/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.sendReport
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`sendReport()`** method of the {{domxref("HIDDevice")}} interface sends an output report to the HID device.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hiddevice/vendorid/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDDevice.vendorId
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`vendorId`** read-only property of the {{domxref("HIDDevice")}} interface returns the vendor ID of the connected HID device. This identifies the vendor of the device.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hidinputreportevent/data/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDInputReportEvent.data
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`data`** property of the {{domxref("HIDInputReportEvent")}} interface returns a {{jsxref("DataView")}} containing the data from the input report, excluding the `reportId` if the HID interface uses report IDs.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hidinputreportevent/device/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDInputReportEvent.device
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`device`** property of the {{domxref("HIDInputReportEvent")}} interface returns the {{domxref("HIDDevice")}} instance that represents the HID interface that sent the input report.

Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/hidinputreportevent/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ status:
browser-compat: api.HIDInputReportEvent
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`HIDInputReportEvent`** interface of the [WebHID API](/en-US/docs/Web/API/WebHID_API) is passed to {{domxref("HIDDevice.inputreport_event", "inputreport")}} event of `HIDDevice` when an input report is received from any associated HID device.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ status:
browser-compat: api.HIDInputReportEvent.reportId
---

{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}
{{securecontext_header}}{{APIRef("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

The **`reportId`** property of the {{domxref("HIDInputReportEvent")}} interface returns the one-byte identification prefix for this report, or 0 if the HID interface does not use report IDs.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ The following Web APIs are available to workers:
- {{domxref("User-Agent Client Hints API", "", "", "nocode")}}
- {{domxref("WebCodecs API", "", "", "nocode")}}
- {{domxref("Web Crypto API", "", "", "nocode")}} (e.g. {{domxref("Crypto")}})
- {{domxref("WebHID API", "", "", "nocode")}} (dedicated and service workers only)
- {{domxref("Web Locks API", "", "", "nocode")}}
- {{domxref("Web Serial API", "", "", "nocode")}}
- {{domxref("Web Periodic Background Synchronization API", "", "", "nocode")}}
Expand Down
2 changes: 1 addition & 1 deletion files/en-us/web/api/webhid_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ status:
browser-compat: api.HID
---

{{DefaultAPISidebar("WebHID API")}}{{SeeCompatTable}}
{{DefaultAPISidebar("WebHID API")}}{{SeeCompatTable}}{{AvailableInWorkers}}

A Human Interface Device (HID) 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.

Expand Down
34 changes: 34 additions & 0 deletions files/en-us/web/api/workernavigator/hid/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: "WorkerNavigator: hid property"
short-title: hid
slug: Web/API/WorkerNavigator/hid
page-type: web-api-instance-property
status:
- experimental
browser-compat: api.WorkerNavigator.hid
---

{{APIRef("WebHID API")}}{{SeeCompatTable}}{{SecureContext_Header}}

The **`WorkerNavigator.hid`**
read-only property returns an {{domxref("HID")}} object providing methods
for connecting to HID devices, listing attached HID devices, and event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connecting to HID devices that were already granted by user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

handlers for connected HID devices.

Where a defined [Permissions Policy](/en-US/docs/Web/HTTP/Permissions_Policy) blocks WebHID usage, the `WorkerNavigator.hid` property will not be available.

## Value

An {{domxref("HID")}} object.

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- [WebHID API](/en-US/docs/Web/API/WebHID_API)
2 changes: 2 additions & 0 deletions files/en-us/web/api/workernavigator/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ _The `WorkerNavigator` interface doesn't inherit any property._
- : Returns the {{domxref("GPU")}} object for the current worker context. The entry point for the {{domxref("WebGPU_API", "WebGPU API", "", "nocode")}}.
- {{DOMxRef("WorkerNavigator.hardwareConcurrency")}} {{ReadOnlyInline}}
- : Returns the number of logical processor cores available.
- {{domxref("WorkerNavigator.hid")}} {{ReadOnlyInline}} {{Experimental_Inline}} {{SecureContext_Inline}}
- : Returns an {{domxref("HID")}} object providing methods for connecting to HID devices, listing attached HID devices, and event handlers for connected HID devices.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connecting to HID devices that were already granted by user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added; I also changed the sentence a bit to improve the grammar generally. I ended up with:

Returns an {{domxref("HID")}} object providing methods for connecting to HID devices already granted permission by the user and listing attached HID devices, and event handlers for responding to HID devices connecting and disconnecting.

Copy link
Collaborator

@wbamberg wbamberg Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was still a bit difficult structurally, and looked into it a bit, and had questions.

It looks to me like HID does not provide a method "for connecting to HID devices", it only provides methods for listing devices and (in the window version only) requesting permission: https://wicg.github.io/webhid/#hid-interface.

It looks like the caveat ("already granted permission by the user") applies to listing devices, and does so for both the window and worker versions of the hid property, but the window version doesn't mention it (https://developer.mozilla.org/en-US/docs/Web/API/Navigator/hid).

So perhaps here we could say something like:

Returns an {{domxref("HID")}} object, which enables a website to list HID devices to which the user has granted access, and be notified when the user agent connects to or disconnects from a HID device.

and in the window version:

Returns an {{domxref("HID")}} object, which enables a website to list HID devices to which the user has granted access, request access to a HID device, and be notified when the user agent connects to or disconnects from a HID device.

?

Also, is it pronounced "hid", like "a HID" or "aych eye dee", like "an HID"? The docs are inconsistent here. FWIW I would expect the former, and the spec seems to agree.

(aside, the redundancy in "HID device" aka "Human Interface Device device", is absolute nails on a chalkboard for me, but I suspect that ship has sailed.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that it's not "just" listing HID devices as web developer can connect to them once they get a HIDDevice. Maybe "communicating with HID devices user has granted access to previously". See https://developer.chrome.com/docs/capabilities/hid#open

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this a bit, and ended up changing the text in both pages to:

...returns an {{domxref("HID")}} object providing methods for accessing HID device connections and events that fire when the user agent connects to or disconnects from a device.

I think saying it more generally like this does away with the need to nitpick about exactly what the methods are doing, and makes for a cleaner, easier-to-read sentence.

I have also checked the HID object and method pages and tweaked their wording slightly to make sure it is clear that getDevices()returns a list of connected devices that the user previous granted access to.

- {{DOMxRef("WorkerNavigator.language")}} {{ReadOnlyInline}}
- : Returns a string representing the preferred language of the user, usually the language of the browser UI. The `null` value is returned when this is unknown.
- {{DOMxRef("WorkerNavigator.languages")}} {{ReadOnlyInline}}
Expand Down
2 changes: 1 addition & 1 deletion files/jsondata/GroupData.json
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@
"HIDConnectionEvent"
],
"methods": [],
"properties": ["Navigator.hid"],
"properties": ["Navigator.hid", "WorkerNavigator.hid"],
"events": []
},
"Web Locks API": {
Expand Down