0

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);
MichaelMao
  • 2,596
  • 2
  • 23
  • 54
mam
  • 87
  • 1
  • 9
  • welcome to stackoverflow mam! i do curious, are you using chrome by any chances? there are many ways `mediaDevices.enumerateDevices()` may fail, see the [other QA](https://stackoverflow.com/questions/43183514/unable-to-get-property-enumeratedevices-of-undefined-or-null-reference). also pretty please post error message as text.. – Bagus Tesa Dec 07 '22 at 04:48
  • @BagusTesa error message : Uncaught TypeError: Cannot read properties of undefined (reading 'enumerateDevices') – mam Dec 07 '22 at 04:59
  • navigator.mediaDevices is exposed to secure contexts only. This means your website needs to be served over HTTPS, not HTTP. – François Beaufort Dec 07 '22 at 07:51

1 Answers1

0

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://.
markmarijnissen
  • 5,569
  • 2
  • 28
  • 34