Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

javascript - Google Chrome v74的设备事件返回未定义(Google Chrome v74's Device Events returning undefined)

I'm trying to use Device Events eg 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.(我正在尝试使用设备事件,例如DeviceMotionEvent和DeviceOrientationEvent,但是当我尝试调试为何它无法在带有chrome 74的更新设备上运行时,上面的事件并未得到读取,并且输出未定义,而不是函数。)

window.addEventListener('devicemotion', function (evt) { console.log(evt); }); window.addEventListener('deviceorientation', function (evt) { console.log(evt); });   ask by virtualbjorn translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use HTTPS.(使用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.(我遇到了同样的问题,经过一些测试后发现它已从http中删除,但仍可用于通过https加载的网站。) Probably related to this issue regarding privacy concerns and this upcoming API .(有关隐私问题和即将发布的API的 问题可能与有关。) iOS/Safari did the same thing in their last update and in addition added a setting turned off by default.(iOS / Safari在上一次更新中做了同样的事情,并且另外添加了默认情况下关闭的设置。) 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).(这篇博客文章似乎表明使用localhost访问网站也可以(将白名单域用于http访问)-但是,如果您使用实际设备进行测试,则不太可能在设备本身上运行服务器,因此以某种方式将您的localhost请求路由到您的服务器ip(仅在您的手机植根于我所知的情况下才能完成)。) Because Generic Sensor API is a powerful feature, Chrome only allows it on secure contexts.(由于通用传感器API是一项强大的功能,因此Chrome仅在安全的上下文中允许它。) In practice it means that to use Generic Sensor API you'll need to access your page through HTTPS.(实际上,这意味着要使用Generic Sensor API,您需要通过HTTPS访问您的页面。) During development you can do so via http://localhost but for production you'll need to have HTTPS on your server.(在开发过程中,您可以通过http:// localhost进行操作,但是对于生产环境,您需要在服务器上安装HTTPS。) See Security with HTTPS article for best practices and guidelines there.(有关最佳做法和指南,请参阅“使用HTTPS进行安全性”文章。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...