Navigator.getGamepads()

This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.

The Navigator.getGamepads() method returns an array: the first value is null, and the others are all Gamepad objects, one for each gamepad connected to the device. So if no gamepads are connected, the method will just return null.

Syntax

 var arrayGP = navigator.getGamepads();

Example

window.addEventListener("gamepadconnected", function(e) {
  var gp = navigator.getGamepads()[0];
  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

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
General support

21.0 webkit
35.0

(Yes) 29.0 (29.0) [1] No support

15.0 webkit
22.0

No support
Feature Android Edge Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
General support No support (Yes) No support No support No support No support

[1] Was available behind a preference since Firefox 24.

See also

Document Tags and Contributors

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