Palak Jadav
Palak Jadav

Reputation: 1272

TypeError: Cannot read property 'getSupportedConstraints' of undefined (when serve on host as IP address)

I am facing a wired issue when i run my angularjs application on my localhost it is working fine. But when I host it on IP address it gives error

TypeError: Cannot read property 'getSupportedConstraints' of undefined

This is my code

let mediaSourceSupport = !!navigator.mediaDevices.getSupportedConstraints()
    .mediaSource;

when serve on localhost navigator.mediaDevices object I get http://prntscr.com/qpf32s but when host on IP address it gives undefind

Upvotes: 2

Views: 2043

Answers (2)

louxiu
louxiu

Reputation: 2915

You can also enable chrome://flags/#unsafely-treat-insecure-origin-as-secure and add your url to it.

Upvotes: 5

Nils Sensken
Nils Sensken

Reputation: 1

This Error will be eliminated when you are running your APP with SSL Encryption on your Production System.

Encryption based security The getUserMedia() method is only available in secure contexts. A secure context is one the browser is reasonably confident contains a document which was loaded securely, using HTTPS/TLS, and has limited exposure to insecure contexts. If a document isn't loaded in a secure context, the navigator.mediaDevices property is undefined, making access to getUserMedia() impossible.

https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Privacy_and_security

Upvotes: 0

Related Questions