Is the HTML5 Gamepad API limited to only 4 Controllers?

Thus far, every time I've used the GamePad API in Chrome, it's returned an array containing four entries initially. The "About:Help" for my version returns the following information:

Version 59.0.3071.115 (Official Build) (64-bit)

When running my code, with one input device attached to my computer, the array contains the following entries:

  • array[0] : GamePad object for my connected device;
  • array[1] : null;
  • array[2] : null;
  • array[3] : null;

At the moment I don't have enough spare USB ports to try plugging in more than 3 devices, so if anyone does have the requisite hardware largesse, it will be an interesting experiment to find out what happens if you attach 5 gamepads to your computer, and see if Chrome creates an array large enough for them all.

One other quirk I've discovered is this. You're supposed to press a button on one of your gamepads/joysticks before running any code that calls the navigator.getGamePads() method. This is a security feature to stop web pages listening for your gamepad details, and sending them off to a malicious entity - if you're lucky enough to have blown a couple of thousand pounds on a realistic F-16 HOTAS unit, you don't want this information being sent to scammers. However, in practice, I've found that this doesn't work on my computer. Even after pressing a button several times, my code pops up the dialogue box I coded to say "No gamepads detected". I then dismiss the dialogue, press a button on the joystick, try again, and hey presto, the detection code registers my devices. Whether this is a Chrome quirk, or is replicated in Firefox, I've yet to test.

A thought occurs to me: when testing your browser code, try pressing a button on EVERY attached device, and see if that results in the GamePad API registering all your devices. Though one issue I can foresee, that might complicate your test, is that you have multiple identical devices connected. If you can find a collection of 8 different gamepads, and try that, you might see different results.

There's a range of issues with the GamePad API at the moment, due to the fact that the W3C standard for this API has yet to be finalised - it's still in the draft stage. As a consequence, different browsers have different implementation details, until the developers thereof have a stable standard to work with.


Ok, I've done some extensive research and testing and feel some confidence in answering this.

The Gamepad API spec doesn't define a limit to controllers, as you can see in the linked documentation above.

In practice, navigator.getGamepads() returns:

  • In Chrome, a GamepadList (this may be a normal Array now?) of 4 undefined values, filled with 4 Gamepad objects.
  • In (Legacy) Edge, an Array of 4 undefined values, filled with 4 Gamepad objects.
  • In Firefox, an Array with length zero, filled with any number of Gamepad objects.

XInput doesn't seem to be the culprit other than maybe influencing the implementation, because I was able to have a mix of inputs beyond four in Firefox that weren't all recognized in the other browsers.

I think this can be chalked up to bad implementation on the part of engines behind Chrome and Edge, and I can only hope they see the light and Firefox keeps their implementation flexible. Ideally the standard lays down the law unambiguously.