I didn't know how to express it in the title, but I'm having an issue with Chrome.
I'm trying to use GetUserMedia()
and GetPosition()
in Chrome. I know that it requires SSL certification first, unless you're on localhost
. The thing is, I can't try my project on my computer, so I must use my smart phone, and in order to access localhost
through my smartphone, I must use the machine's IP address (192.168.1.4). The problem is that Chrome doesn't consider this IP address as localhost
, so it requires an SSL certificate.
Is there any way I can test my project on my smartphone without having to install an SSL certififcate?
Insecure origins treated as secure setting
.Go to chrome://flags/#unsafely-treat-insecure-origin-as-secure
in Chrome.
Find the Insecure origins treated as secure setting
.
Enable it.
Enter in http://cntral.me:3000
.
Relaunch Chrome.
Voila!
See https://medium.com/@Carmichaelize/enabling-the-microphone-camera-in-chrome-for-local-unsecure-origins-9c90c3149339 for a good walkthrough as well.
You can do this without an SSL certificate at all by tunneling the webserver to your phone's localhost.
I use termux to run this command (on the phone itself):
ssh -L 8080:localhost:8080 192.168.0.172
(Leave the ssh session open)
Then go to http://localhost:8080/ on your phone.
If you don't want the session to time out, you can use autossh:
autossh -M 0 -L 8080:localhost:8080 192.168.0.172
Important note: Your development machine (or dev server) needs to be accessible through ssh. For Linux, this can be done by installing open-ssh and enabling/starting the sshd service. You can look up guides for this online.
You can use a service like https://ngrok.com/ to map a public DNS address with SSL certificate to a port on your local machine.
I assume you're trying to host a Web service on a computer and access it from a smart phone using the hostname localhost
.
Two options come to mind:
First, if your smart phone is rooted, you can change /etc/hosts
so that the name localhost
resolves to 192.168.1.4
instead of to 127.0.0.1
.
Second, if you can run an SSH server on your computer, you can set up an SSH client on your phone to forward traffic on some port to another port on a different machine.
For example, in ConnectBot for Android, you can
192.168.1.4
8080
) and on the bottom line, use localhost:80
(or whatever port the computer is running the service on) to make the SSH server have the forwarding tunnel direct to itself on port 80This will cause all traffic directed at localhost:8080
on your phone to go to 192.168.1.4:80
on your computer. The browser has no idea that the localhsot:8080
service is actually just an SSH tunnel to 192.168.1.4:80
, so it will treat it like any other localhost
address.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With