简体   繁体   English

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

[英]Webcam js Error in Chrome: Could not access webcam

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.它在 Chrome 和 Firefox 中运行良好。 But lately webcam error started showing only in CHROME.但最近网络摄像头错误开始仅在 CHROME 中显示。 Firefox still works fine. 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://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features

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

Chrome 47 requires that the site be HTTPS in order for user media / webcam to work! Chrome 47 要求网站是 HTTPS 以便用户媒体/网络摄像头工作! This is a brand new requirement that I didn't see coming...这是一个全新的要求,我没有看到......

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.这意味着我必须购买 SSL 证书。 The library should work fine in Chrome 47, as long as you are using it on 127.0.0.1, or over HTTPS.只要您在 127.0.0.1 或 HTTPS 上使用该库,该库在 Chrome 47 中应该可以正常工作。

Issue Discussion问题讨论

Solution解决方案

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-secure in Chrome.chrome://flags/#unsafely-treat-insecure-origin-as-secure导航到chrome://flags/#unsafely-treat-insecure-origin-as-secure

  • Find and enable the Insecure origins treated as secure section (see below).查找并启用Insecure origins treated as secureInsecure origins treated as secure部分(见下文)。

  • 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。

See here! 看这里!

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

I also got this error.我也收到了这个错误。

Solution:解决方案:

Make sure that your website is secured.确保您的网站是安全的。 Access it via https protocol.通过https协议访问它。

Example:例子:

Use采用

https://example.azurewebsites.net/ 

Instead of代替

http://example.azurewebsites.net/

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.转到 C:\\Program Files\\Google\\Chrome\\Application 或浏览器的安装目录。

  • You will find 2 different files out there: chrome.exe and old_chrome.exe.您会在那里找到 2 个不同的文件:chrome.exe 和 old_chrome.exe。 Rename chrome.exe to any other name and then rename the old_chrome.exe to chrome.exe将 chrome.exe 重命名为任何其他名称,然后将 old_chrome.exe 重命名为 chrome.exe

  • Launch Google Chrome启动谷歌浏览器

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM