admin管理员组文章数量:1400211
I am currently trying to use the WebRTC api and have everything working locally.
When I deploy to surge.sh
I lose access to the navigator.mediaDevices
object. How can I resolve this?
The following line of code is where I am having trouble with.
const stream = await navigator.mediaDevices.getDisplayMedia({video: {mediaSource: 'screen'}});
I receive the following error message:
TypeError: Cannot read property 'getDisplayMedia' of undefined
I am currently trying to use the WebRTC api and have everything working locally.
When I deploy to surge.sh
I lose access to the navigator.mediaDevices
object. How can I resolve this?
The following line of code is where I am having trouble with.
const stream = await navigator.mediaDevices.getDisplayMedia({video: {mediaSource: 'screen'}});
I receive the following error message:
TypeError: Cannot read property 'getDisplayMedia' of undefined
Share
Improve this question
asked Jun 17, 2019 at 2:04
M.NarM.Nar
6511 gold badge10 silver badges26 bronze badges
3
-
2
You need https.
navigator.mediaDevices
is only available in SecureContext now in Chrome and in the spec. – jib Commented Jun 17, 2019 at 2:21 - Ahhh. Thank you. I had read something similar to that and it was not clear what the solution was. – M.Nar Commented Jun 17, 2019 at 2:31
- Glad it resolved your issue. Adding it as an answer. – jib Commented Jun 17, 2019 at 17:47
2 Answers
Reset to default 7You need https.
navigator.mediaDevices
is only available in SecureContext now in Chrome 74, Firefox 68, and in the spec, which means the object will be missing in insecure contexts (http).
As jib answered, navigator.mediaDevices
is not available when webserver uses HTTP scheme while not hosted on localhost
, but with an exception in chrome/chromium:
$ chromium --unsafely-treat-insecure-origin-as-secure=http://WEBSERVER_FQDN:PORT_NUMBER
--unsafely-treat-insecure-origin-as-secure
mand line option allows to loosen the restriction. It's useful for developing/debugging when HTTPS is not set up yet or you need to analyze raw unencrypted HTTP messages (i.e. wireshark).
本文标签:
版权声明:本文标题:javascript - I do not have have access to navigator.mediaDevices when the site is deployed. How do I fix this? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744168561a2593667.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论