This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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

 var gamepads = navigator.getGamepads();

Example

window.addEventListener("gamepadconnected", function(e) {
  var gp = navigator.getGamepads()[e.gamepad.index];
  console.log(
    "Gamepad connected at index %d: %s. %d buttons, %d axes.",
    gp.index, gp.id, gp.buttons.length, gp.axes.length
  );
});

Specifications

Specification Status Comment
Gamepad
The definition of 'The Gamepad API specification' in that specification.
Working Draft Initial definition.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
getGamepads
Experimental
Chrome Full support 35
Full support 35
Full support 21
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Edge Full support 12Firefox Full support 29IE No support NoOpera Full support 22
Full support 22
Full support 15
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Safari No support NoWebView Android Full support 37
Full support 37
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Chrome Android Full support 42Edge Mobile Full support YesFirefox Android No support NoOpera Android No support NoSafari iOS No support NoSamsung Internet Android ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

See also

Document Tags and Contributors

Contributors to this page: Stuk, connorshea, Nektro, abbycar, chrisdavidmills, teoli
Last updated by: Stuk,