Some browser features only work in classic localhost

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the web-development category.

Last Updated: 2024-11-23

I had a Laravel project served on http://192.168.10.10 locally. When I tried to use camera features in the browser, it failed.

Why?

The browser camera won't work with non-HTTPS locally due to demands of MediaDevices.getUserMedia in the browser security model. The object will literally be undefined in that context.

The solution

# VIRTUAL MACHINE:
#
# During provisioning, copy the SSL cert out of Vagrant for use in the main system (giving local SSL)
cp /etc/nginx/ssl/ca.homestead.shield-doc-backend.crt /home/vagrant/code/secrets
# HOST MACHINE (macOS)

# Trust the cert we copied out
security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain `pwd`/secrets/ca.homestead.my-backend.crt