Issue metadata
Sign in to add a comment
|
Deviceorientation events are not firing after switching the protocol
Reported by
andrej.p...@gmail.com,
Sep 20
|
||||||||||||||||||||
Issue description
Steps to reproduce the problem:
1. Setup a server that is able to serve attached file via HTTP and HTTPS.
2. Open the website in Chrome on Android on HTTP.
3. Tilt the device, the box is moving.
4. Change the URL so that it points to the HTTPS.
5. The box is not moving.
6. Add top.addEventListener('deviceorientation', function () {}); at the start of the script tag.
7. Refresh the page, the box is moving moving.
8. Remove top.addEventListener('deviceorientation', function () {}); and refresh the page.
9. The box is still moving.
10. Change the protocol again to HTTP.
11. The box is not moving.
What is the expected behavior?
The box should be moving regardless of the protocol or if we switch between them.
What went wrong?
I have a page with an iframe. In the context of the iframe I execute some JS code that attaches a deviceorientation listener to the iframe's window object. With the listener attached I then control a div's position.
I can refresh the page numerous times and everything will work as expected. But if I change the protocol from HTTP to HTTPS (or vice-versa), the deviceorientation events stop firing. If I then first attach another deviceorientation listener to the top window (the handler can be empty), the events start to fire again. If I always attach another listener to the top window, I can switch the protocol without any problems. As soon as I remove the listener from top window, refresh the page and switch the protocol, the problem occurs again.
Did this work before? Yes 68
Does this work in other browsers? Yes
Chrome version: 69.0.3497.100 Channel: stable
OS Version: 6.0.1
Flash Version:
It doesn't matter if we first serve on HTTPS, what breaks the behavior is the switching.
A workaround is to attach an empty deviceorientation listener on the top window object.
I tried multiple Android versions (6.0.1, 7.0, 8.0, 8.0.1). The code worked as expected in Chrome <= 68 and had unwanted behavior in Chrome 69.
,
Oct 9
,
Oct 10
odejesush@ to reproduce.
,
Oct 10
,
Oct 11
I have been able to reproduce the issue with a small difference to the given steps. The box does not move initially until a listener is added to the top level frame. Once the listener is added, the box will move. I can remove the listener and refresh multiple times and the box will still move. From this point, performing the steps to reproduce behaves exactly as described.
,
Oct 25
Any progress on this? The workaround stopped working on Chrome 70.
,
Oct 25
I have only reproduced it. I plan to investigate it more closely soon.
,
Oct 29
Also running into this issue, Is there a timeframe for this issue getting fixed?
,
Oct 29
The issue is being investigated. We cannot provide a timeline for delivering a fix until the root cause is known.
,
Nov 5
Workaround for Chrome >= v70 would be to catch events on the top window and dispatch them to an iframe's window.
top.addEventListener('deviceorientation', function (evt) {
var syntheticEvent = new Event('deviceorientation', { 'bubbles': true, 'cancelable': true });
syntheticEvent.alpha = evt.alpha;
syntheticEvent.beta = evt.beta;
syntheticEvent.gamma = evt.gamma;
iframeWindow.dispatchEvent(syntheticEvent);
});
,
Nov 6
I tested the sample page using a Pixel 3. The bug occurs in the current stable release of Chrome 70.0.3538.80. However, it seems to have been fixed in the beta release of Chrome 71.0.3578.31 and onward.
,
Nov 7
andrej.premrn@, please check if the bug still occurs in a beta, dev, or canary release of Chrome. I will run a bisect to figure out the cause of the bug. Thank you
,
Nov 16
It feels like this could be related to this bug: https://bugs.chromium.org/p/chromium/issues/detail?id=783586 > The device motion/orientation events now use the the same backend as the generic sensors API. This broke these events in cross-origin iframes because of checks to prevent such usage in the generic sensors API. I assume some restrictions that have been placed on Generic Sensor API invocation may also be incorrectly being applied to 'deviceorientation', 'devicemotion' and 'deviceorientationabsolute' event listener handling? Interesting side-note: It seems injecting _sourceless_ iframe contents (e.g. injecting code via 'srcdoc' or 'document.write') is preventing these device motion and orientation events from firing, even thought sourceless iframes belong to the top-level page's origin and should be able to receive these events. All other versions of Chrome on Android (< version 70) and all browsers on iOS have always correctly flowed device motion and orientation events in to such sourceless iframes. Chrome 70 has broken this flow for the first time among browsers and I expect a lot of code is affected (e.g. motion sensor dependent code loaded in SafeFrames: https://www.iab.com/guidelines/safeframe/).
,
Nov 16
> All other versions of Chrome on Android (< version 70) and all browsers on iOS have always correctly flowed device motion and orientation events in to such sourceless iframes. Chrome 70 has broken this flow for the first time I just want to clarify that even if you "warm-up" the device sensors in Chrome 70 (according to the injection via 'srcdoc' as described in this initial bug report comment) the sensors still do not work. If you "warm-up" the device sensors in Chrome < 70 (according to the injection via 'srcdoc' as described in this initial bug report comment) the sensors will work.
,
Nov 16
Adding the following files to provide demonstrations of the bugs addressed in my previous comment: `iframe_motion_srcdoc_test.html - sourceless iframe injection via `srcdoc`, "warm-up" the sensors prior to calling `srcdoc` and then run a devicemotion event test within that injected iframe. iframe_motion_documentwrite_test.html - sourceless iframe injection via `document.write`, "warm-up" the sensors prior to calling `document-write` and then run a devicemotion event test within that injected iframe. In Chrome < 70 for Android both demos print: "Motion events are flowing" thanks to the "warm-up" workaround suggested in this bug. In Chrome 70 for Android both demos print: "Motion events are not flowing" despite the "warm-up" workaround suggested in this bug.
,
Nov 16
Demo files:
,
Nov 16
Rich, per comment #12 can you verify whether this issue has been fixed in Chrome 71. We are working on a bisect to determine what broke (and fixed) this issue and we want to make sure that it really is working in all the cases people have reported.
,
Nov 20
This bug was introduced by the following commit: https://chromiumdash.appspot.com/commit/94c082d42d63ce1e43c126057c627dfedf2990bd and was fixed by the following commit: https://chromiumdash.appspot.com/commit/5e9f806410de4daa95cc0f57061e12270391fdff Upon further investigation, I found that the first commit changed the permission check to use PermissionManager::RequestPermission. This eventually failed in PermissionContextBase::RequestPermission because the requesting origin passed into this method was invalid [1]. The requesting origin was retrieved in SensorProviderProxyImpl::GetSensor using RenderFrameHost::GetLastCommittedURL. Therefore, it seems that this method returns an empty URL when the iframe is loaded using srcdoc. The reason that the second commit fixed the bug is because the commit enables Permission Delegation, which requires users to only make permission decisions about the top level origin of a website. PermissionManager::RequestPermission uses PermissionManager::GetCanonicalOrigin to determine the requesting origin to use in the actual permission request. When the Permission Delegation flag is enabled, this method returns the embedding origin. [2] As a result, the requesting origin is valid, since it is now the embedding origin. [1]https://cs.chromium.org/chromium/src/chrome/browser/permissions/permission_context_base.cc?l=124 [2] https://cs.chromium.org/chromium/src/chrome/browser/permissions/permission_manager.cc?l=341 |
|||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||
Comment 1 by chelamcherla@chromium.org
, Sep 21