navigator.getGamepads() returns an array of Gamepad objects — one slot per connected controller (MDN). Slots may be null after a disconnect so other pads keep the same index.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call navigator.getGamepads. Start with this line.
JavaScript
navigator.getGamepads()
Call
What it does
navigator.getGamepads()
Primary signature.
navigator.getGamepads(...)
Call with the arguments your case needs.
Built into the browser. Call getGamepads(...) on a Navigator — no import required.
Library declarations
JavaScript
navigator.getGamepads()
Parameters
This member has no parameters beyond those shown in the signature.
Return Value
Return Value
Description
*
Gamepad[] (may contain null)
JavaScript Examples
Example 1 — Feature Detection
Check whether getGamepads exists before using the Gamepad API.
Schedule with rAF. Matches the display refresh for smooth games.
Re-call getGamepads(). Each frame needs a fresh snapshot.
Count active pads. Filter out null before using length.
Stop the demo. Real games keep polling while the scene is active.
Compatibility
Browser Support
navigator.getGamepads() is part of the Gamepad API and is Baseline Widely available since March 2017. Controllers often need a button press before they appear in the array. A Permissions Policy can still block access.
✓ Baseline · Widely available
Navigator.getGamepads()
Snapshot array of Gamepad objects — poll for live buttons and axes.
95%Modern browser support
Google ChromeGamepad API · Baseline
Supported
Microsoft EdgeGamepad API · Baseline
Supported
Apple SafariGamepad API · Baseline
Supported
OperaGamepad API · Baseline
Supported
Mozilla FirefoxGamepad API · Baseline
Supported
Internet ExplorerNo Gamepad API
Unavailable
getGamepads()Excellent
Bottom line: Safe for modern web games. Listen for gamepadconnected, skip null slots, and poll getGamepads() in your animation loop.
Frequently Asked Questions
It returns an array of Gamepad objects for controllers connected to the device. Some slots may be null if a pad disconnected, so remaining pads keep the same index.
No. MDN marks it Baseline Widely available (since March 2017). It is not Deprecated, Experimental, or Non-standard — no status banner is required.
Many browsers only expose gamepads after the user presses a button on the controller (privacy / gesture). Listen for gamepadconnected, then call getGamepads().
If a gamepad disconnects mid-session, its slot may become null so other pads keep stable indexes. Always skip null entries when looping.
Use gamepad.buttons (pressed / value) and gamepad.axes (usually -1 to 1). Poll getGamepads() each animation frame for continuous input.
Yes. A SecurityError can be thrown if use is blocked by a Permissions Policy.