[Gamepad] Pages using only navigator.getGamepads without event listeners don't get gamepad data

VERIFIED FIXED in mozilla28

Status

()

VERIFIED FIXED
5 years ago
10 days ago

People

(Reporter: ted, Assigned: ted)

Tracking

Trunk
mozilla28
x86_64
Windows 7
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

This is silly, but apparently the machinery to scan for gamepads and update the DOM only triggers if you add event listeners for gamepadconnected or gamepaddisconnected. Calling navigator.getGamepads isn't sufficient, which means that pages doing strictly polling won't actually get any gamepad data.

The simple workaround is just to add
addEventListener("gamepadconnected", function() {});

which will make things spin up.
This fixes this issue for me on a simple local test page. Unfortunately I can't write a test for this because all of the Mochitests use a fake gamepad service, which means they don't need to spin up a platform gamepad service anyway. Conveniently the patch is trivial.
Attachment #8342342 - Flags: review?(bugs)
Assignee: nobody → ted
Status: NEW → ASSIGNED
Comment on attachment 8342342 [details] [diff] [review]
pages using only navigator.getGamepads should trigger gamepad backend startup

A bit hackish, but mostly because SetHasGamepadEventListener name is odd.
We should change that to WantsGamepadUpdates() or some such, and
then have another method for the 'false' case, perhaps
DisconnectedFromGamepadService()

But you can do that in a followup.
Attachment #8342342 - Flags: review?(bugs) → review+
Filed bug 947172 on renaming that method.
https://hg.mozilla.org/mozilla-central/rev/20a6f6176960
Status: ASSIGNED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla28

Updated

5 years ago
Keywords: verifyme
Posted file testcase
Here's a testcase you can use for verification. Connecting a gamepad and pressing a button on this page should display a message in the page body.

Comment 7

5 years ago
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0

With Nightly from 2013-11-06 no message is displayed.
On latest Aurora (Build ID:20140203004003) a message is displayed in the page body of the attached testcase when a button is pressed on the gamepad. Tested with Xbox 360 and Logitech F310 controllers.
Status: RESOLVED → VERIFIED
Keywords: verifyme
Component: DOM → DOM: Core & HTML
Product: Core → Core
You need to log in before you can comment on or make changes to this bug.