<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>284375</bug_id>
          
          <creation_ts>2024-12-10 09:28:22 -0800</creation_ts>
          <short_desc>[visionOS] &quot;gamepadconnected&quot; event does not fire unless gamepad permission has already been given to Safari</short_desc>
          <delta_ts>2026-04-17 10:59:17 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>Other</version>
          <rep_platform>Vision Pro</rep_platform>
          <op_sys>visionOS 2</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alec Bargas">abargas</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>adachan</cc>
    
    <cc>beidson</cc>
    
    <cc>brandonstewart</cc>
    
    <cc>phyllis</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2080522</commentid>
    <comment_count>0</comment_count>
      <attachid>473523</attachid>
    <who name="Alec Bargas">abargas</who>
    <bug_when>2024-12-10 09:28:22 -0800</bug_when>
    <thetext>Created attachment 473523
minimal repro page

On visionOS 2, the &quot;gamepadconnected&quot; 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 &quot;gamepadconnected&quot; 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 &quot;gamepadconnected&quot; event is fired.
5. Observe that no permissions dialog to give gamepad permissions appears in Safari window.

The expected behavior is that either the &quot;gamepadconnected&quot; event fires or the dialog appears when the gamepad is connected and the &quot;gamepadconnected&quot; event fires after accepted.

Reproduces with:
Version/18.0.1 Safari/605.1.15 (visionOS 2.0.1 physical device)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2082367</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-12-17 09:29:14 -0800</bug_when>
    <thetext>&lt;rdar://problem/141623162&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2082882</commentid>
    <comment_count>2</comment_count>
    <who name="">phyllis</who>
    <bug_when>2024-12-18 19:38:52 -0800</bug_when>
    <thetext>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&apos;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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2199993</commentid>
    <comment_count>3</comment_count>
    <who name="Aleksei Marchenko">aleksei</who>
    <bug_when>2026-04-13 18:27:47 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/62694</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2201588</commentid>
    <comment_count>4</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-04-17 10:59:15 -0700</bug_when>
    <thetext>Committed 311465@main (19ddb1eeb7ce): &lt;https://commits.webkit.org/311465@main&gt;

Reviewed commits have been landed. Closing PR #62694 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>473523</attachid>
            <date>2024-12-10 09:28:22 -0800</date>
            <delta_ts>2024-12-10 09:28:22 -0800</delta_ts>
            <desc>minimal repro page</desc>
            <filename>index.html</filename>
            <type>text/html</type>
            <size>3191</size>
            <attacher name="Alec Bargas">abargas</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sIHN0eWxlPSJoZWlnaHQ6IDEwMCU7Ij4KICAgIDxoZWFkPgog
ICAgICAgIDx0aXRsZSBpZD0idGl0bGUiPkdhbWVwYWQgQ29ubmVjdCBTYW1wbGU8L3RpdGxlPgog
ICAgICAgIDxsaW5rIHJlbD0ibWFuaWZlc3QiIGhyZWY9Im1hbmlmZXN0Lmpzb24iIGNyb3Nzb3Jp
Z2luPSJ1c2UtY3JlZGVudGlhbHMiIC8+CiAgICAgICAgPG1ldGEKICAgICAgICAgICAgbmFtZT0i
dmlld3BvcnQiCiAgICAgIC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UlkKCJjb25uZWN0ZWRjb3VudCIpOwogICAgICAgICAgICAgICAgY29ubmVjdGVkQ291bnROdW1i
ZXIudmFsdWUgPSBwYXJzZUludChjb25uZWN0ZWRDb3VudE51bWJlci52YWx1ZSkgKyAxOwogICAg
ICAgICAgICAgICAgcG9sbElkID0gd2luZG93LnNldEludGVydmFsKGNoZWNrQ29ubmVjdGVkR2Ft
ZXBhZHMsIDEwMCk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICB3aW5kb3cuYWRkRXZlbnRM
aXN0ZW5lcigiZ2FtZXBhZGRpc2Nvbm5lY3RlZCIsKCkgPT4gewogICAgICAgICAgICAgICAgaWYg
KCFhcmVBbnlHYW1lcGFkc0Nvbm5lY3RlZCgpKSB7CiAgICAgICAgICAgICAgICAgICAgd2luZG93
LmNsZWFySW50ZXJ2YWwocG9sbElkKTsKICAgICAgICAgICAgICAgICAgICBwb2xsSWQgPSAwOwog
ICAgICAgICAgICAgICAgICAgIGNoZWNrQ29ubmVjdGVkR2FtZXBhZHMoKTsKICAgICAgICAgICAg
ICAgIH0KICAgICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICA8L3NjcmlwdD4KPC9odG1sPgo=
</data>

          </attachment>
      

    </bug>

</bugzilla>