簡體   English   中英

Chrome 中的網絡攝像頭 js 錯誤:無法訪問網絡攝像頭

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

我在我的一個項目中使用網絡攝像頭 JS。

https://github.com/jhuckaby/webcamjs

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

它在 Chrome 和 Firefox 中運行良好。 但最近網絡攝像頭錯誤開始僅在 CHROME 中顯示。 Firefox 仍然可以正常工作。

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

我升級了版本,現在我在 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

我的網站有一個安全的來源。

誰能告訴我為什么我會面臨這樣的錯誤?

我相信復制粘貼 webcam.js 代碼沒有意義。

這是我使用的代碼:

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 要求網站是 HTTPS 以便用戶媒體/網絡攝像頭工作! 這是一個全新的要求,我沒有看到......

有關該主題的 Chromium 文檔: https : //www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features

這意味着我必須購買 SSL 證書。 只要您在 127.0.0.1 或 HTTPS 上使用該庫,該庫在 Chrome 47 中應該可以正常工作。

問題討論

解決方案

您可以允許特定站點或端口:

要忽略 Chrome 的安全來源政策,請按照以下步驟操作。

  • chrome://flags/#unsafely-treat-insecure-origin-as-secure導航到chrome://flags/#unsafely-treat-insecure-origin-as-secure

  • 查找並啟用Insecure origins treated as secureInsecure origins treated as secure部分(見下文)。

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

  • 保存並重新啟動 Chrome。

看這里!

如果您還不能提供安全連接,您所能做的就是使用后備閃存。 使用該庫中的配置代碼:

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

我也收到了這個錯誤。

解決方案:

確保您的網站是安全的。 通過https協議訪問它。

例子:

采用

https://example.azurewebsites.net/ 

代替

http://example.azurewebsites.net/

對於此類問題,還有另一種方法可以在開發過程中幫助我,並且可能對其他人有所幫助。 解決方案是將 Google Chrome 的版本降級到 46 次。

以下是基本步驟: - 關閉 Google Chrome 中的更新

  • 轉到 C:\\Program Files\\Google\\Chrome\\Application 或瀏覽器的安裝目錄。

  • 您會在那里找到 2 個不同的文件:chrome.exe 和 old_chrome.exe。 將 chrome.exe 重命名為任何其他名稱,然后將 old_chrome.exe 重命名為 chrome.exe

  • 啟動谷歌瀏覽器

您可以在此處找到更詳細的說明: 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