Reputation: 1412
On my website, I've had some Javascript that's been running perfectly fine for over a year now (and I pride myself on it working in every browser, as far as I can tell). But recently it suddenly broke and after some debugging I found this.
I have some code that creates an eventHandler as follows:
window.addEventListener(
'devicemotion',
function (e) { ... },
false
);
This handler is used to handle device accelerations, but for some reason, as of some recent Chrome update this handler is getting called on all my computers (laptop, desktop, etc.) instead of just my mobile devices. As far as I know, none of these devices have any accelerometers in them, and this handler was never executed on them in the past.
Could anyone shed some light on why this behavior has changed? It seems pretty counter-intuitive for this handler to ever get called on a desktop computer. I tried searching for updates in Chrome that talk about this, but I'm not really familiar with searching Chrome or Chromium repos/source code.
Upvotes: 2
Views: 1560
Reputation: 9202
According to r196645 google wanted to fix the support for the device motion part of the Device Orientation API.
The W3C specification draft said:
Implementations that are unable to provide all three angles must set the values of the unknown angles to null. If any angles are provided, the absolute property must be set appropriately. If an implementation can never provide orientation information, the event should be fired with all properties set to null.
To correct this part of the Device Orientation API they opened r263415
and told chrome to fire the devicemotion
event on all devices and just pass null values as specified in the W3C specification draft.
So that's why this behavior changed.
Upvotes: 2
Reputation: 4167
What about if you wrap the listener inside an if browser width / navigator statement? I know it's not ideal but a lot of things do seem to be going wrong with chrome lately. I'm currently suffering from an incurable bug (or that's how it seems) where my console remains constantly blank and I have to use canary for any debugging tasks.
Upvotes: 0