Firefox 98:
navigator.getGamepads()
only containsGamepad
objects, and only for gamepads that are actually connected.- When handling a
gamepadconnected
event, the event'sgamepad
property is a live reference to the gamepad in question. It can be saved and used to check for future changes to the gamepad state. - While handling a
gamepaddisconnected
event, the array obtained fromnavigator.getGamepads()
will still include the gamepad being disconnected, but will report it as having 0 buttons and 0 axes. - I have only ever seen index 0 be assigned to the first-connected gamepad.
Chrome 100:
navigator.getGamepads()
contains four items, which arenull
until a gamepad is actually connected. (I expect this is a minimum and the array will expand if you connect five or more gamepads, but I haven't tested it.)