Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome v74's Device Events returning undefined

I'm trying to use Device Events e.g DeviceMotionEvent and DeviceOrientationEvent but when I tried debugging why it wouldn't work on my updated device with chrome 74 is turns out the above events is not getting read and the output is undefined instead of a function.


window.addEventListener('devicemotion', function (evt) {
   console.log(evt);
});
window.addEventListener('deviceorientation', function (evt) {
   console.log(evt);
});
like image 310
virtualbjorn Avatar asked Apr 30 '19 07:04

virtualbjorn


Video Answer


1 Answers

Use HTTPS. I ran into the same issue and after some testing discovered that this has been removed from http but is still available for sites loaded over https.

Probably related to this issue regarding privacy concerns and this upcoming API.

iOS/Safari did the same thing in their last update and in addition added a setting turned off by default.

I couldn't find it mentioned anywhere in the changes list or any public official changelog though.

This blog post seems to indicate that accessing the site using localhost would also work (whitelisted domain for http access) - however if you are testing using an actual device, it is unlikely that you are running your server on the device itself so you will have to somehow route your localhost requests to your server ip (which can only be done if your phone is rooted as far as I know).

Because Generic Sensor API is a powerful feature, Chrome only allows it on secure contexts. In practice it means that to use Generic Sensor API you'll need to access your page through HTTPS. During development you can do so via http://localhost but for production you'll need to have HTTPS on your server. See Security with HTTPS article for best practices and guidelines there.

like image 157
Bali Balo Avatar answered Nov 04 '22 17:11

Bali Balo