safari 13.1 navigator.mediaDevices.enumerateDevices() return only audio devices

1.7k views Asked by At

Im facing with an issue on desktop Safari 13.1 version. If I open the console in the web inspector (with a regular macbook which has webcam and mic) and execute this command on any kind of website:

navigator.mediaDevices.enumerateDevices()

First time it will return in the Promise result with a videoinput and an audioinput. Second time it will return only 2 audioinput. Videoinput is disappear.

Unfortunately I call this method several times while checking the available devices on my solution.

Any idea why does it happen and how could I get the accurate information about the devices even If I call it more than once? See the results here

1

There are 1 answers

0
Daniel Crisp On

I've found the same issue, also on my iPad running iOS 13.

It seems you need to request camera access first in order to see the correct device list.

navigator.mediaDevices.getUserMedia({ video: true })

This will prompt you for access to the camera (you need to be on HTTPS or localhost).

Grant permission, then run this again and you should see the videoinput device(s) listed in the returned promise:

navigator.mediaDevices.enumerateDevices()

I guess this makes sense as a privacy feature that a website cannot check if a camera exists without first asking your permission.