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

VERIFIED FIXED in mozilla28

Status

()

Core
DOM
VERIFIED FIXED
4 years ago
3 years ago

People

(Reporter: ted, Assigned: ted)

Tracking

Trunk
mozilla28
x86_64
Windows 7
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

(Assignee)

Description

4 years ago
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.
(Assignee)

Comment 1

3 years ago
Created attachment 8342342 [details] [diff] [review]
pages using only navigator.getGamepads should trigger gamepad backend startup

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)

Updated

3 years ago
Assignee: nobody → ted
Status: NEW → ASSIGNED

Comment 2

3 years ago
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+
(Assignee)

Comment 3

3 years ago
https://hg.mozilla.org/integration/mozilla-inbound/rev/20a6f6176960
(Assignee)

Comment 4

3 years ago
Filed bug 947172 on renaming that method.
https://hg.mozilla.org/mozilla-central/rev/20a6f6176960
Status: ASSIGNED → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla28

Updated

3 years ago
Keywords: verifyme
(Assignee)

Comment 6

3 years ago
Created attachment 8368499 [details]
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

3 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
You need to log in before you can comment on or make changes to this bug.