This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
* Some parts of this feature may have varying levels of support.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
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 DOMException
Use 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.`,
);
});
| Specification |
|---|
| Gamepad> # dom-navigator-getgamepads> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
getGamepads |
3521 | 12 | 29 | 2215 | 10.1 | 3525 | 32 | 2214 | 10.3 | 3.01.5 | 374.4 | 10.3 |
secure_context_required |
86 | 86 | 91 | 72 | No | 86 | No | No | No | No | No | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getGamepads