Search code examples
javascripthtmlgamepadgamepad-api

Is the HTML5 Gamepad API limited to only 4 Controllers?


I'm correctly able to get input from 4 controllers through using the HTML5 Gamepad API within a browser.

https://www.w3.org/TR/gamepad/

What I'm having trouble with is getting input from 8 controllers. These being all Xbox 360 controllers, I know there's a legacy limit to the XInput API. But looking at the HTML5 API documentation above, I can't see anything mentioning a limit or how the API is implemented.

navigator.getGamepads(); seems to return an array of 4 undefined spots in Chrome and Edge, and an unspecified array in FireFox that still seems to go to a limit of 4.

You can see Windows 10 verifies I have 8 controllers connected in the Devices panel, and all work individually up to 4 gamepads within the browser. So I'm questioning why the Gamepad API is limiting me here - is it by design of the Gamepad API, or XInput?

8 Controllers Connected


Solution

  • 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.