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 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.
Syntax
getGamepads()
Parameters
None.
Return value
Exceptions
SecurityError
DOMException
-
Use of this feature was blocked by a Permissions Policy.
Examples
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 |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getGamepads | ||||||||||||||
Secure context required |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- User must explicitly enable this feature.
- Requires a vendor prefix or different name for use.
- Has more compatibility info.