Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.DeviceMotionEvent is undefined on my phone

Here is the entirety of my code:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
  </head>
  <body>
  </body>
  <script>
    alert(!!window.DeviceMotionEvent);
  </script>
</html>

On my phone this page alerts "false." On my desktop it alerts "true." I'm running the page on localhost with just a python SimpleHTTPServer and connecting to the IP and port directly over WiFi. I'm using mobile Chrome version 74.0.3729.157 on a Samsung Galaxy S7.

I'm at a total loss. Can anyone think of ANY reason it would ever be undefined? Google is giving me nothing on this.

like image 227
Vanessa Argodale Avatar asked Sep 04 '25 17:09

Vanessa Argodale


1 Answers

Okay, I found the answer and I'm going to leave this up because, trust me, there are ZERO OTHER google results for this question.

According to a google blog post from 2017:

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.

So that was the issue. It worked on localhost like it says but I couldn't connect to it from anywhere else because python SimpleHTTPServer is just that, an HTTP server. Not HTTPS. And because I was using a version of Chrome on my phone.

like image 170
Vanessa Argodale Avatar answered Sep 07 '25 08:09

Vanessa Argodale



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!