chrome 报错 navigator.mediaDevices is undefined

What? chrome will report an error? Your code is wrong!

chrome 报错 navigator.mediaDevices is undefined

Recently, I am developing a camera project (multi-person meeting, camera is needed~~). Then my colleague’s computer was debugged well, and an error was reported to me. My chrome version is always up to date. Why is it not compatible with me?

It turns out that the content will become more and more strict in the future.
Chrome: Want to call the camera? Yes, httpsshow me your certificate

Solve the problem

After all, it is impossible to have https certificates everywhere, you have to debug locally, and there will always be localhost domain names. So I found such an article: MediaDevices.getUserMedia` undefined problem

Then I will make a record myself

Solution 1

Start Chrome with the corresponding parameters

For example, we are debugging the link: http://example.com. If there are multiple URLs, ,separate them with

 --unsafely-treat-insecure-origin-as-secure="http://example.com"

Where to add it?

Note that there is a space in front

Solution 2 (Recommend this)

  • chrom down

打开 chrome://flags/#unsafely-treat-insecure-origin-as-secure

  • Select enabled
  • Fill in the URL to be debugged, multiple URLs are separated by
  • Complete restart chrome onset of action (following there will be changed after a relaunchbutton)

Found after restarting, it can be non- httpsdebugging

  • under edge

After all, now the edge is the same as the chrome kernel, so the operation method is the same, except that the link is different: edge://flags/#unsafely-treat-insecure-origin-as-secure


At this point, the problem is solved. If you want to use it online, you still need it https. Now it is difficult to do without https

Guess you like

Origin blog.csdn.net/Jioho_chen/article/details/109345783