Unable to get property 'enumerateDevices' of undefined or null reference

Koby Douek picture Koby Douek · Apr 3, 2017 · Viewed 7.1k times · Source

I'm using enumerateDevices (See reference here) to get the user's camera and microphones list.

This code works great on Chrome:

$(document).ready(function(){
    navigator.mediaDevices.enumerateDevices()
    .then(gotDevices)
});

But since it's unsupported on IE, it throws an error:

Unable to get property 'enumerateDevices' of undefined or null reference

My question: Is there any alternative I can use that works across all browsers?

Answer

Bhojendra Rauniyar picture Bhojendra Rauniyar · Apr 25, 2020

navigator.mediadevices can also be undefined in insecure context.

You need to have https: instead of http:


There's some experiment flags on chrome to allow it:

chrome://flags/#allow-insecure-localhost

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