部署站点时,我无权访问 navigator.mediaDevices.我该如何解决? [英] I do not have have access to navigator.mediaDevices when the site is deployed. How do I fix this?

查看:92
本文介绍了部署站点时,我无权访问 navigator.mediaDevices.我该如何解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用 WebRTC api 并让一切都在本地运行.当我部署到 surge.sh 时,我无法访问 navigator.mediaDevices 对象.我该如何解决?

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'}});

我收到以下错误消息:

TypeError: Cannot read property 'getDisplayMedia' of undefined

推荐答案

您需要 https.

navigator.mediaDevices 现在仅在 Chrome 中的 SecureContext 中可用 74, Firefox "https://www.fxsitecompat.dev/en-CA/docs/2019/getusermedia-and-enumeratedevices-can-no-longer-be-used-on-insecure-sites" rel="nofollow noreferrer">68,以及规范,其中意味着对象将在不安全的上下文 (http) 中丢失.

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).

这篇关于部署站点时,我无权访问 navigator.mediaDevices.我该如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆