11

Im trying to enable microphone to allow user record audio, but I get this error:

Uncaught TypeError: Cannot read property 'getUserMedia' of undefined at activateMicrophone

navigator.mediaDevices.getUserMedia({audio: true, video:false})
            .then(stream => {
                handlerFunction(stream, $audioSelect.siblings(".recordedAudio"));
                $(".record").prop("disabled", false);
            })
pzsette
  • 286
  • 1
  • 5
  • 19
  • Hello! For us to help you better, I think the version of your Google Chrome would be useful to know. You can also post the value of `navigator.userAgent` instead. Otherwise, I am pretty sure `navigator.mediaDevices.getUserMedia` is a function offered by Chrome (and Firefox, and some other user agents as per one or the other standardized Web API). – Armen Michaeli Nov 05 '19 at 17:38
  • 1
    Version 76.0.3809.132 (64 bit) – pzsette Nov 05 '19 at 17:53

1 Answers1

23

Grabbing navigator.mediaDevices as of Chrome 74 requires a secure context.

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/mediaDevices

This means that non https:// requests will return an undefined object.

For more information on this change: https://w3c.github.io/mediacapture-main/#local-content

Bitz
  • 1,128
  • 11
  • 33
  • I believe you linked wrong resource -- MDN doesn't say anything about how access to `mediaDevices` from scripts from insecure origins is handled. What you want to link to is https://w3c.github.io/mediacapture-main/#local-content – Armen Michaeli Nov 05 '19 at 18:50
  • The browser compatibility section covers the change with respect to secure contexts and Chrome versioning. Your link does actually cover the change explicitly but doesn't cover the browsers for which the changes are effective. I will include both resources as an edit. Thanks! – Bitz Nov 05 '19 at 18:59