Gamepad API in Chrome App

963 views
Skip to first unread message

Rich Mayfield

unread,
Jun 17, 2015, 4:54:37 PM6/17/15
to chromium-...@chromium.org
I'm trying to integrated the Gamepad API into one of my apps. I had this working last year, but it seems to have broken since. Here's where I'm at:

  • Enabled Experimental API in chrome://flags
  • Got "experimental" permissions in manifest.json
I was able to set the following listeners:

window.addEventListener("gamepadconnected", Joystick.connect);
window.addEventListener("gamepaddisconnected", Joystick.disconnect);

The callback functions are called in the following situations:
  1. Joystick is plugged into USB and a button is pressed
  2. Joystick is disconnected from USB
Then, I try to poll the gamepads using:

var gamepad = navigator.getGamepads();

This returns an object or array with 4 undefined entries:

GamepadList
  0: undefined
  1: undefined
  2: undefined
  3: undefined
  length: 4
  __proto__: GamepadList
What is the proper way to get the gamepad state? 
There are two problems I'm having:
  1. gamepadconnected doesn't fire if a gamepad is already connected and you press a button. It only fires if you plug a device in and then press a button.
  2. navigator.getGamepads() doesn't seem to return expected results

Rich Mayfield

unread,
Jun 17, 2015, 5:12:45 PM6/17/15
to chromium-...@chromium.org
Apparently this is the correct way to poll gamepads. However, if the API is somehow broken by bad coding, you have to restart chrome in order to bring it back to life.

So, my question now becomes: 
Is there a way to "close" connections to gamepads?
Is there a way to reset the API instead of a browser reset?

Rich Mayfield

unread,
Jun 18, 2015, 1:07:55 PM6/18/15
to chromium-...@chromium.org
Playing around with this a little more makes me think that there's either something wrong with the API or I'm using it wrong.

If I reload my app, or close it, the next time I open the API is broken. The only remedy is to completely restart chrome. 

Is there anyone out there who's developing support for the Gamepad API? Is this a feature that we're going to see fully implemented?

Jean-François Geyelin

unread,
Jul 6, 2015, 7:22:26 AM7/6/15
to chromium-...@chromium.org

Rich Mayfield

unread,
Jul 6, 2015, 11:15:14 PM7/6/15
to chromium-...@chromium.org
Right. That's describes the behavior, but no solutions.

Steve Atherton

unread,
Nov 21, 2016, 4:34:37 AM11/21/16
to Chromium-Extensions-Announce, nocti...@gmail.com
Any solution to this?  I've run into exactly the same problem.  I want to make a Chrome App that uses both gamepads and UDP.  I have to use an App to be able to use UDP, but the Gamepad API apparently doesn't work in Apps.

This must have worked at one time because there is a Chrome App sample that uses the Gamepad API (https://github.com/GoogleChrome/chrome-app-samples/tree/master/samples/parrot-ar-drone) but it no longer works either.
Reply all
Reply to author
Forward
0 new messages