Navigator.getGamepads()

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

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox 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 35
Full support 35
Full support 25
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox Android No support NoOpera Android Full support 22
Full support 22
Full support 14
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Safari iOS No support NoSamsung Internet Android Full support 3.0
Full support 3.0
Full support 1.5
Prefixed
Prefixed Implemented with the vendor prefix: webkit

Legend

Full support
Full support
No support
No support
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