navigator.mediaDevices.getUserMedia is not working and neither does webkitGetUserMedia

后端 未结 4 1495
名媛妹妹
名媛妹妹 2020-12-29 04:11

I\'ve been using webkitGetUserMedia method (getUserMedia through adapter.js) to get the camera nad microhpone for webRTC on my web app. My server is not secure (no SSL certi

相关标签:
4条回答
  • 2020-12-29 04:24

    As per new chrome update (From Google Chrome 47), getUserMedia() is no longer supported in chrome browser over http:// (Unsecure Origin) , It will work on https:// (Secure Origin)

    For development purpose,

    1.localhost is treated as a secure origin over HTTP, so if you're able to run your server from localhost, you should be able to test the feature on that server.

    2.You can run chrome with the --unsafely-treat-insecure-origin-as-secure="http://example.com" flag (replacing "example.com" with the origin you actually want to test), which will treat that origin as secure for this session. Note that you also need to include the --user-data-dir=/test/only/profile/dir to create a fresh testing profile for the flag to work.

    reference: https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

    0 讨论(0)
  • 2020-12-29 04:28

    The last google-chrome update makes getUserMedia work only on secure origins. There is a method to make it work, but only for developing purposes. Just run chrome using cmd with thoses options

    --unsafely-treat-insecure-origin-as-secure="example.com"

    and this option to use a new user profile

    --user-data-dir=/test/only/profile/dir

    FYI getUserMedia work on firefox until now, but in my opinion, it will recommend a secure origin like google-chrome.

    0 讨论(0)
  • 2020-12-29 04:28

    You can still use the old method name in Chrome 47, as long as you use https. The name change is orthogonal to 47's new secure-origin requirement. See other answers.

    On the missing methods: navigator.mediaDevices.getUserMedia was put back under a flag in Chrome, so you must either turn on chrome://flags/#enable-experimental-web-platform-features or use a recent version of adapter.js, like here: https://stackoverflow.com/a/34230983/918910.

    0 讨论(0)
  • 2020-12-29 04:47

    While testing on my phone on with a local server, I was struggling to get mic permissions for my pwa on android chrome. (Was working fine on my desktop.) Some of the above suggestions helped push me in the right direction, but I want clarify just a bit. ...Chrome on my phone was not allowing the permissions request to fire because the origin address was not secure. I found this article on the subject which was very helpful: Enabling the Microphone/Camera in Chrome for (Local) Unsecure Origins by Scott Carmichael.

    He says,

    1. Navigate via address-bar to chrome://flags/#unsafely-treat-insecure-origin-as-secure in Chrome.

    2. Find and enable the Insecure origins treated as secure section.

    3. Add any addresses you want to ignore the secure origin policy for. (Include the port number if required.)

    4. Save and restart Chrome.

    0 讨论(0)
提交回复
热议问题