How to allow Chrome to access my camera on localhost?

前端 未结 9 2156
庸人自扰
庸人自扰 2020-11-29 03:10

I cloned a project about real-time image processing on a web browser from this link: Then I could not allow my browser to access my camera. I got this javascript alert:

相关标签:
9条回答
  • 2020-11-29 03:40

    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

    0 讨论(0)
  • 2020-11-29 03:44

    Step 1: Find your chrome preferences file: http://www.forensicswiki.org/wiki/Google_Chrome#Configuration

    Step 2: Open it and Find the "profile" key

    Step3: Under profile there will be a "content_settings" hash, that will have a "pattern_pairs" hash Add this to it:

      "*,*": {
        "media-stream-camera": 1
      }
    

    Final example:

    "profile": {
       ....
       "content_settings": {
          ....
          "pattern_pairs": {
             "*,*": {
                "media-stream-camera": 1
             },
             ....
          }
        }
    }
    

    WARNING: This will allow all websites access to your camera

    0 讨论(0)
  • 2020-11-29 03:44

    Another solution is to use iframe tag. Jest deploy your page on server (localhost or external) and include it in your local html. Example:

    <iframe src="http://localhost/your_project/index.html"></iframe>
    
    0 讨论(0)
提交回复
热议问题