New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 736289 link

Starred by 11 users

Issue metadata

Status: Fixed
Owner:
Closed: Oct 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug


Show other hotlists

Hotlists containing this issue:
Gamepad


Sign in to add a comment

Re-filing: Gamepad API does not work in a popup window

Reported by a...@scirra.com, Jun 23 2017

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36

Steps to reproduce the problem:
I am re-filing  issue 711252  because it appears nobody has responded to it since we filed it in April. Our users keep running in to this issue repeatedly with our PWA:

https://github.com/Scirra/Construct-3-bugs/issues/64
https://github.com/Scirra/Construct-3-bugs/issues/345
https://github.com/Scirra/Construct-3-bugs/issues/462
https://github.com/Scirra/Construct-3-bugs/issues/548

Please look in to this bug, it's a persistent problem and nobody from Chrome is even looking at our report.

1. Plug in a gamepad and visit https://www.scirra.com/labs/gamepaddemo/ and verify the gamepad is recognised
2. Visit https://editor.construct.net
3. In the search field (under the Construct 3 logo), type "gamepad"
4. Double-click the "gamepad control" demo that is listed
5. Click the "Play" button in the toolbar at the top, and approve any popup window prompts
6. Try to use gamepad input in the popup window

What is the expected behavior?
Gamepad API to work.

What went wrong?
Gamepad API does not work. The demo remains on "no gamepad detected".

Did this work before? N/A 

Does this work in other browsers? Yes

Chrome version: 59.0.3071.109  Channel: stable
OS Version: 10.0
Flash Version: 

It appears the gamepad API only works if the full tabbed browser UI is showing. This breaks gamepad mode in Construct 3's game preview.

It actually works again if the page is in an iframe in a popup - if you click the "debug" button next to "preview" in Construct 3, it shows the game in an iframe and gamepad input works again. So actually it's only top-level frames in popup windows that don't work.
 

Comment 2 by hdodda@chromium.org, Jun 28 2017

Cc: hdodda@chromium.org
Components: Blink>GamepadAPI
Labels: Needs-Feedback
Tested the issue on windows 10 & 7 using chrome M59 #59.0.3071.115 and canary M61 #61.0.3142.3 and followed below steps:

1. launched chrome and connected logitech f310 gamepad and navigated to https://www.scirra.com/labs/gamepaddemo/ .
2. Once the gamepad is detected ,opened new tab and opened https://editor.construct.net.
3. In the search field (under the Construct 3 logo), typed "gamepad"
4. Double-clicked the "gamepad control" demo that is listed
5. Clicked the "Play" button in the toolbar at the top, and approved any popup window prompts
6. Observed that no gamepad detected.

Attached screencast for reference.

@ash-- Could you please confirm if this is the issue you are talking about or if we have missed any steps in reproducing the issue and help us by providing the expected result screenshot or video, for better understanding.


Thanks!
736289.mp4
5.1 MB View Download
Labels: Needs-Triage-M59

Comment 4 by a...@scirra.com, Jun 29 2017

That is indeed the issue, the video is just about right but the issue only reproduces when using the normal Run button (in the video the Debug button is clicked instead).

We just published an update that accidentally works around this by changing the URL of the preview to a different origin. This issue still reproduces if you use this URL instead:

https://editor.construct.net/r41/

So it seems the issue is if you open a popup window on the same origin as the page, the top-level frame in the popup cannot access any gamepads. You can verify in the popup in the console that navigator.getGamepads() only returns an array of null entries, even after trying to use the gamepad.
Project Member

Comment 5 by sheriffbot@chromium.org, Jun 29 2017

Labels: -Needs-Feedback
Thank you for providing more feedback. Adding requester "hdodda@chromium.org" to the cc list and removing "Needs-Feedback" label.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot

Comment 6 by a...@scirra.com, Jun 29 2017

I also tried to reproduce the issue in a minimal test, but it worked. There must be something different about Construct 3 that breaks it.
Labels: Needs-Feedback
@ash--- We are not able to get what you are exactly trying to communicate .. Could you please prvide us the screencast of the steps to reproduce the issue , that would help in better understanding.

Screencast tool :
https://screencast-o-matic.en.softonic.com/

Thanks!
This is failing because NavigatorGamepad can't get an execution context. In NavigatorGamepad::StartUpdatingIfAttached we grab the context and cast it to a Document. In the failing case, this context is NULL; in the accidental workaround, it finds the context and casts successfully.
Owner: mattreynolds@chromium.org
Status: Started (was: Unconfirmed)
Cc: pnangunoori@chromium.org
 Issue 711252  has been merged into this issue.
Thanks to japhet@ for figuring this out. NavigatorGamepad gets the LocalFrame via the ExecutionContext, which it accesses through the ContextLifecycleObserver interface. In some cases, the ExecutionContext can be NULL even when the DOMWindow is still active.

From ContextLifecycleObserver.h:

// There is a subtle difference between the timing when the context gets
// detached and the timing when the window gets detached. In common cases,
// these two happen at the same timing. The only exception is a case where
// a frame navigates from an initial empty document to another same-origin
// document. In this case, a Document is recreated but a DOMWindow is reused.
// Hence, in the navigated document ContextClient::getExecutionContext()
// returns null while DOMWindowClient::domWindow() keeps returning the window.

We're hitting this case because the popup is initially created with an empty document and then navigates to a same-origin document. To fix, NavigatorGamepad should access the LocalFrame through the DOMWindowClient interface, which will continue to return the correct LocalFrame and DOMWindow even after the empty document is destroyed.
Project Member

Comment 12 by bugdroid1@chromium.org, Oct 10 2017

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/4fca553939af1d2d33a49c4ca2df1727a020be09

commit 4fca553939af1d2d33a49c4ca2df1727a020be09
Author: Matt Reynolds <mattreynolds@google.com>
Date: Tue Oct 10 21:45:51 2017

Fix "Gamepad API does not work in a popup window"

NavigatorGamepad previously accessed the LocalFrame and LocalDOMWindow
through the ExecutionContext provided through the
ContextLifecycleObserver interface. In some cases the ExecutionContext
returned by the interface method is NULL while the DOMWindow is still
active. This can occur when a window navigates from an empty document
to a same-origin document. The ExecutionContext is recreated but the
window is reused.

This CL fixes this issue by instead having NavigatorGamepad access the
LocalFrame and LocalDOMWindow through the DOMWindowClient interface,
which will return the correct frame and window when the
ExecutionContext is destroyed.

BUG= 736289 

Change-Id: I5f26f05b7599c1b708f1ddc358949fb872a9a8ec
Reviewed-on: https://chromium-review.googlesource.com/667864
Commit-Queue: Matt Reynolds <mattreynolds@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#507782}
[modify] https://crrev.com/4fca553939af1d2d33a49c4ca2df1727a020be09/third_party/WebKit/Source/modules/gamepad/NavigatorGamepad.cpp
[modify] https://crrev.com/4fca553939af1d2d33a49c4ca2df1727a020be09/third_party/WebKit/Source/modules/gamepad/NavigatorGamepad.h

Status: Fixed (was: Started)

Sign in to add a comment