Javascript Chrome 中的网络摄像头 js 错误:无法访问网络摄像头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34081919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:53:19  来源:igfitidea点击:

Webcam js Error in Chrome: Could not access webcam

javascriptgoogle-chromewebcamwebcam.js

提问by Sajeev C

I am using Webcam JS in one of my projects.

我在我的一个项目中使用网络摄像头 JS。

https://github.com/jhuckaby/webcamjs

https://github.com/jhuckaby/webcamjs

version I was using: 1.0.0 Latest version available: 1.0.5

我使用的版本:1.0.0 可用的最新版本:1.0.5

It was working fine in both Chrome and Firefox. But lately webcam error started showing only in CHROME. Firefox still works fine.

它在 Chrome 和 Firefox 中运行良好。但最近网络摄像头错误开始仅在 CHROME 中显示。Firefox 仍然可以正常工作。

Error that I received in 1.0.0: Webcam.JS Error: cannot access webcam.

我在 1.0.0 中收到的错误: Webcam.JS Error: cannot access webcam.

I upgraded the version and now the error I'm getting in chrome is

我升级了版本,现在我在 chrome 中遇到的错误是

Webcam.js Error: Could not access webcam.
Permission Error: Only secure origins are allowed

https://goo.gl/Y0ZkNV

https://goo.gl/Y0ZkNV

I website has a secure origin.

我的网站有一个安全的来源。

Can anyone tell me why I'm facing errors like that?

谁能告诉我为什么我会面临这样的错误?

I believe there's no point in copy pasting webcam.js code.

我相信复制粘贴 webcam.js 代码没有意义。

Here's the code i use:

这是我使用的代码:

Webcam.set({
      width: 320,
     height: 240,
     dest_width: 320,
     dest_height: 240,
     image_format: 'jpeg',
     jpeg_quality: 90,
     force_flash: false
    });
    Webcam.attach( '#my_camera' );

回答by Sajeev C

Chrome 47 requires that the site be HTTPS in order for user media / webcam to work! This is a brand new requirement that I didn't see coming...

Chrome 47 要求网站是 HTTPS 以便用户媒体/网络摄像头工作!这是一个全新的要求,我没有看到......

Chromium Docs on the topic: https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features

有关该主题的 Chromium 文档:https: //www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features

This means I'll have to buy a SSL cert. The library should work fine in Chrome 47, as long as you are using it on 127.0.0.1, or over HTTPS.

这意味着我必须购买 SSL 证书。只要您在 127.0.0.1 或 HTTPS 上使用该库,该库在 Chrome 47 中应该可以正常工作。

Issue Discussion

问题讨论

Solution

解决方案

回答by orafaelreis

If you can't provide a secure connection yet, all you can do is use the fallback to flash. Use the config code in that lib:

如果您还不能提供安全连接,您所能做的就是使用后备闪存。使用该库中的配置代码:

 Webcam.set({
        force_flash: true
 });

回答by Abdul Mujeeb

Webcam.set({
    width: 500,
    height: 400,
    image_format: "jpeg",
    jpeg_quality: 90,
    force_flash: false,
    flip_horiz: true,
    fps: 45
});

Webcam.set("constraints", {
    optional: [{ minWidth: 600 }]
});

回答by Augusto Cruz

You can permitted a specific site or port:

您可以允许特定站点或端口:

To ignore Chrome's secure origin policy, follow these steps.

要忽略 Chrome 的安全来源政策,请按照以下步骤操作。

  • Navigate to chrome://flags/#unsafely-treat-insecure-origin-as-securein Chrome.

  • Find and enable the Insecure origins treated as securesection (see below).

  • Add any addresses you want to ignore the secure origin policy for. Remember to include the port number too (if required).

  • Save and restart Chrome.

  • chrome://flags/#unsafely-treat-insecure-origin-as-secure在 Chrome 中导航到。

  • 找到并启用该Insecure origins treated as secure部分(见下文)。

  • 添加要忽略其安全源策略的任何地址。请记住也包括端口号(如果需要)。

  • 保存并重新启动 Chrome。

See here!

看这里!

回答by VJPPaz

I also got this error.

我也收到了这个错误。

Solution:

解决方案:

Make sure that your website is secured. Access it via httpsprotocol.

确保您的网站是安全的。通过https协议访问它。

Example:

例子:

Use

https://example.azurewebsites.net/ 

Instead of

代替

http://example.azurewebsites.net/

回答by johannesMatevosyan

There is another approach for this kind of issue which helped me during the development and might be helpful for others. The solution is to downgrade the version of Google Chrome to the 46-th.

对于此类问题,还有另一种方法可以在开发过程中帮助我,并且可能对其他人有所帮助。解决方案是将 Google Chrome 的版本降级到 46 次。

Here are the basic steps: - Turn off updates in Google Chrome

以下是基本步骤: - 关闭 Google Chrome 中的更新

  • Go to C:\Program Files\Google\Chrome\Application or to the directory where your browser was installed.

  • You will find 2 different files out there: chrome.exe and old_chrome.exe. Rename chrome.exe to any other name and then rename the old_chrome.exe to chrome.exe

  • Launch Google Chrome

  • 转到 C:\Program Files\Google\Chrome\Application 或浏览器的安装目录。

  • 您会在那里找到 2 个不同的文件:chrome.exe 和 old_chrome.exe。将 chrome.exe 重命名为任何其他名称,然后将 old_chrome.exe 重命名为 chrome.exe

  • 启动谷歌浏览器

You can find more detailed instruction here: http://ipswitchft.force.com/kb/articles/FAQ/How-to-downgrade-to-an-Older-version-of-Chrome

您可以在此处找到更详细的说明:http: //ipswitchft.force.com/kb/articles/FAQ/How-to-downgrade-to-an-Older-version-of-Chrome