通用传感器 API 在本地主机上不工作

Generic Sensor API not working on localhost

我正在尝试在我的项目中使用通用传感器 API(陀螺仪)我已经查找了有关 W3C 和 Intel Github 和 https://mobiforge.com/design-development/the-generic-sensor-api 的文档 我已经 created/copied https://mobiforge.gitlab.io/sensors/gyroscope.html this HTML page to reference javascript it works fine when i open with this link or my github link: Screen Shot of my github page nishanksisodiya.github.io/gyro

但是当我在我的笔记本电脑上使用烧瓶服务器 运行 打开它时,它显示 Gyroscope not supported 错误 Screen Shot my localhost page

    let status = document.getElementById('status');
    if ( 'Gyroscope' in window ) {
        let sensor = new Gyroscope();
        sensor.addEventListener('reading', function(e) {
            status.innerHTML = 'x: ' + e.target.x + '<br> y: ' + e.target.y + '<br> z: ' + e.target.z;
        });
        sensor.start();
    }
    else status.innerHTML = 'Gyroscope not supported';

这是我用过的javascript。 任何帮助将不胜感激。

我自己在使用通用传感器 api 时遇到了很多困难,并发现 rarely mentioned 其工作的要求之一是必须在安全的环境中使用。这意味着托管域的 SSL 证书。哪个...会使本地开发变得非常困难,对吗?

好吧,我找到了解决方法 localtunnel

部署,但是...是另一回事。一段时间以来,我遇到了一些问题,现在将它移到我已经研究了多年的这个 React 应用程序上的 webpack 开发服务器之外。非常感谢任何帮助。

PS:我发现的最奇怪的东西,它应该 only be supported by Chrome version 67+. But go ahead and click on this link 与任何其他移动浏览器一起工作,并且可以正常工作。只是。美好的。 ???