Search code examples
javascripthtmlgetusermedia

What do I need, to make getUserMedia() work?


I am pretty new to javascript, and I want to make use of getUserMedia(). When I go on this page everything works fine for me, chrome is asking me to allow access to my camera. But when I download source code of their site from their github and try to run that code locally, it doesn't work. Do I need anything additional to make it work? How can I debug that?


Solution

  • You need to run the files from a webserver and not the local file-system, otherwise you'll get an error like this:

    navigator.getUserMedia error:  NavigatorUserMediaError {code: 1, PERMISSION_DENIED: 1}
    

    Chrome comes with an excellent set of tools for debugging. The first thing you should do is hit F12 to launch them (assuming you're on Windows) and check the console for any errors. Then take the time to play around and familiarise yourself with the tools; they will be very useful to you ;).