-
It can be tricky to test Javascript code on mobile when you’re using Web APIs that require a secure (HTTPS) context, e.g. the DeviceOrientationAbsolute event.
If my webserver is serving on
localhost:8080
, my usual method to test on mobile is to just go to my laptop’s IP address + port in my phone’s browser, e.g.Âhttp://192.168.1.153:8080
.But on my phone, this isn’t a localhost address and it isn’t https, so it’s not secure, and the API doesn’t work.
ngrok is a SAAS way to solve this, but I just learned an easy work-around.
Go to
chrome://flags
in Chrome on your phone (also works in Brave) and search for a flag called “Insecure origins treated as secure”.If you enter your computers’s ip address+port combination into the textbox, enable the flag, and then restart your browser, your context will now be marked as secure, and your JS APIs will work!
(A word of warning: don’t do this for real websites, security contexts are important!)
Hopefully this will save someone a headache down the line!
Discuss on Mastodon