How to Allow Chrome to Access My Camera on Localhost

How to allow Chrome to access my camera on localhost?

Are you accessing the webpage that is served over HTTP, on localhost? If you are accessing it from http://localhost/... , Chrome will ask for your permission to use the camera.

Chrome accessing camera on localhost

If you are opening the web page directly, i.e. /Users/Methuz/Documents/index.html then it will not work, even if you explicitly allows it permission

Chrome cannot access camera over file protocol


In this case, the workaround I use is to host the HTML file on a webserver. A quick hack is to use python, in the folder where the HTML page is lcoated: python -m SimpleHTTPServer

Camera access works on localhost but fails on chrome on server with https

After some research, we were able to find that the reason the camera was being blocked on the testing environment was due to the feature policy header. In our application, it's added via asp.net web.config, since we don't have this on localhost it would work normally.

This will completely block access to camera:

<add name="Feature-Policy" value="camera 'none'" />

In order to enable and allow the browser to request permission, we need to have it as:

<add name="Feature-Policy" value="camera 'self'" />

Browser says "Camera Blocked to protect your privacy"

  1. type url chrome://flags/#unsafely-treat-insecure-origin-as-secure
  2. Enter url in the textarea
  3. Choose Enabled in the select option
    Click image link bellow to see detail

example

JavaScript GetUserMedia using Chrome with localhost without HTTPS

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.



Related Topics



Leave a reply



Submit