一切福田,不離方寸,從心而覓,感無不通。

调用摄像头拍照chrome浏览器报Cannot read properties of undefined (reading 'getUserMedia')

一、背景:

项目中使用电脑摄像头拍照,调用navigator.mediaDevices方法,在本地正常,测试环境和生产环境报错。

二、原因:

navigator.mediaDevices在目前以下情况中可以获取到

1.地址为localhost://访问

2.协议为https

3.为文件访问file:///

测试环境和生产环境使用的都是http协议,因此无法调用

三、解决方法

1.在chrome地址栏输入chrome://flags/#unsafely-treat-insecure-origin-as-secure

2.在Insecure origins treated as secure的输入框输入要打开网页的地址如http://xx.xx.xx:8080

3.把右边的Disnabled改成Enabled

4.点右下角的Relaunch

 

转自于:https://hepuhua.cn/post/942.html#

 

from:https://www.cnblogs.com/Ao-min/p/18644211