1

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);
3
  • 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. also pretty please post error message as text.. Commented Dec 7, 2022 at 4:48
  • @BagusTesa error message : Uncaught TypeError: Cannot read properties of undefined (reading 'enumerateDevices') Commented Dec 7, 2022 at 4:59
  • navigator.mediaDevices is exposed to secure contexts only. This means your website needs to be served over HTTPS, not HTTP. Commented Dec 7, 2022 at 7:51

1 Answer 1

1

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://.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.