WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
284375
[visionOS] "gamepadconnected" event does not fire unless gamepad permission has already been given to Safari
https://bugs.webkit.org/show_bug.cgi?id=284375
Summary
[visionOS] "gamepadconnected" event does not fire unless gamepad permission h...
Alec Bargas
Reported
2024-12-10 09:28:22 PST
Created
attachment 473523
[details]
minimal repro page On visionOS 2, the "gamepadconnected" event does not fire unless Safari has already been given permission to access the gamepad. This permission dialog can be prompted by calling navigator.getGamepads from a page. However, since the "gamepadconnected" events do not fire without the permission, it requires a page to be preemptively calling navigator.getGamepads even if it does not think gamepads are connected. This behavior can be seen with the minimal test page attached. The steps to reproduce the behavior are: 1. Disconnect all gamepads from the Vision Pro. 2. Load test page. 3. Connect a gamepad to the Vision Pro and press buttons. 4. Observe that no "gamepadconnected" event is fired. 5. Observe that no permissions dialog to give gamepad permissions appears in Safari window. The expected behavior is that either the "gamepadconnected" event fires or the dialog appears when the gamepad is connected and the "gamepadconnected" event fires after accepted. Reproduces with: Version/18.0.1 Safari/605.1.15 (visionOS 2.0.1 physical device)
Attachments
minimal repro page
(3.12 KB, text/html)
2024-12-10 09:28 PST
,
Alec Bargas
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2024-12-17 09:29:14 PST
<
rdar://problem/141623162
>
phyllis
Comment 2
2024-12-18 19:38:52 PST
Adding more details to this issue - what happens on AVP is this: - The first time we call `navigator.getGamepads()`, Safari prompts user for permission via a banner. The call synchronously returns an array with no meaningful elements `[null,null,null,null]`. - If we call `navigator.getGamepads()` before permission is granted, it continues to return that array. - There is no API for us to actively query the permission state. Neither is there a callback function to be invoked when permission is granted or denied. - Even if the gamepad is connected via bluetooth, no `gamepadconnected` event will be emitted before permission is granted. Below is what I feel could be a bit troublesome to deal with: To trigger `gamepadconnected` event, **both** conditions must be met: a. User presses a button on the gamepad after granting permission (this is to mitigate fingerprinting, as specified in
https://www.w3.org/TR/gamepad/
) b. `navigator.getGamepads()` is called again When the above conditions are met, `gamepadconnected` event is emitted. Subsequent `navigator.getGamepads()` calls return an array with gamepad information. The order of actions in steps a and b can be interchanged, but both must occur for the `gamepadconnected` event to fire. If b happens first, the event is emitted when user presses a button on the gamepad. If a happens first, the event is emitted right after the next `navigator.getGamepads()` call returns (NOT when you press the button). Which is really weird, because that is not the time gamepad is connected, not the time gamepad is invoked (via a button press), nor the time permission is granted. It just so happens to randomly emit an event and the fact that gamepadconnected event only fires after a specific API call (and therefore the timing depends on when the client calls the API) doesn't seem to make much sense... You can use this for a repro on AVP device with VisionOS 2+:
https://escapiststupor.github.io/gamepad-test
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug