cannot read property ''enumerateDevices' of undefined over http

803 views Asked by At

I create asp.net web application and copy code from https://webrtc.github.io/samples/src/content/getusermedia/canvas/ and public project to iis link http://123.111.1.222/test/camera.aspx not working is error

This is the error message Uncaught TypeError: Cannot read properties of undefined (reading 'enumerateDevices'

code here

    navigator.mediaDevices.enumerateDevices().then(gotDevices).catch(handleError);
1

There are 1 answers

0
markmarijnissen On

You need to be on https:// or localhost for navigator.mediaDevices to be available.

For security purposes, accessing mediaDevices on http:// is not allowed. Therefore, you receive an error that it cannot find the fuction enumerateDevices, because indeed, mediaDevices is undefined.

Solutions, from easy to hard:

  • Use localhost as your development server.
  • Tunnel your local server using a tool such as ngrok or localtunnel, which will act as a https to http proxy.
  • Upload your app to a server supporting https.
  • Add SSL certificates to your development server, and access using https://.