The Navigator.getGamepads() method returns an array of Gamepad objects, one for each gamepad connected to the device.
Elements in the array may be null if a gamepad disconnects during a session, so that the remaining gamepads retain the same index.
getGamepads()None.
An Array of Gamepad objects, eventually empty.
SecurityError DOMExceptionUse of this feature was blocked by a Permissions Policy.
window.addEventListener("gamepadconnected", (e) => {
const gp = navigator.getGamepads()[e.gamepad.index];
console.log(
`Gamepad connected at index ${gp.index}: ${gp.id} with ${gp.buttons.length} buttons, ${gp.axes.length} axes.`,
);
});