9

After updating from Chrome 73 to 74 navigator.getUserMedia and navigator.webkitGetUserMedia return undefined.

Here https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getUserMedia I see that getUserMedia is actually deprecated in favor of navigator.mediaDevices.getUserMedia(), but in my case navigator.mediaDevices too is undefined so I cannot use it.

Anyone knows if it's a bug in the latest release of Chrome or if I need to use something else?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Mauro Piccotti
  • 1,807
  • 2
  • 23
  • 34

3 Answers3

16

Since version 74 of Chrome navigator.getUserMedia, navigator.webkitGetUserMedia and navigator.mediaDevices can be used only in secure context (https), otherwise they are undefined.

I've understood what the problem was while writing the question, as usual...

Mauro Piccotti
  • 1,807
  • 2
  • 23
  • 34
5

I tried a small setting on chrome and it turned out to work for me.

I enabled: chrome://flags/#unsafely-treat-insecure-origin-as-secure

and provided my HTTP server link along with the port.

It worked for me.

You could refer to the following: 1. https://stackoverflow.com/a/61472984/12906501 2. https://medium.com/@Carmichaelize/enabling-the-microphone-camera-in-chrome-for-local-unsecure-origins-9c90c3149339

Hope it helps!! Thanks.

  • 2
    Sounds hazardous. – greybeard Apr 28 '20 at 09:25
  • I'm not sure what the state was when this asnwer/comment were added, but Chrome at least now requires you to whitelist specific sites and doesn't even appear to allow wildcarding in the URLs. For development on your own site that's being served over HTTP locally, this seems fine. If this blindly allowed all sites to access the camera/mic even over HTTP, yes, that would be hazardous. – Carcigenicate May 26 '23 at 15:21
1

In my case HTTP was the cause of undefined for navigator.mediaDevices

with HTTPS works as expected

Alex
  • 8,908
  • 28
  • 103
  • 157