Navigator: getGamepads() method
Baseline Widely available *
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 insecure contexts (HTTPS), in some or allsupporting browsers.
TheNavigator.getGamepads() method returns an array ofGamepad objects, one for each gamepad connected to the device.
Elements in the array may benull if a gamepad disconnects during asession, so that the remaining gamepads retain the same index.
In this article
Syntax
js
getGamepads()Parameters
None.
Return value
Exceptions
SecurityErrorDOMExceptionUse of this feature was blocked by aPermissions Policy.
Examples
js
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.`, );});Specifications
| Specification |
|---|
| Gamepad> # dom-navigator-getgamepads> |