javascript - Google Chrome v74's Device Events returning undefined - Stack Overflow

I'm trying to use Device Events e.g DeviceMotionEvent and DeviceOrientationEvent but when I tried

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);
});

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);
});
Share Improve this question asked Apr 30, 2019 at 7:58 virtualbjornvirtualbjorn 711 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

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 uping 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745277656a4620129.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信