Languages

React - webcam doesn't work on mobile device

0 points
Asked by:
Gigadude
791

I have a React project that uses react-webcam.

Everything works fine on localhost:3000 but when I open the project using http://192.168.xx.xx:3000/ in Chrome on the mobile device it doesn't stream the video or show any pop-up to allow the use of the camera.

How can I enable the camera on the mobile device then?

1 answer
0 points
Answered by:
Admin Dirask Community
4380

Quick solution

1. In Chrome on mobile device go to:

2. Enable the Insecure origins treated as secure,

3. Add addresses you want to ignore including the port number.

Problem explanation

The problem is security policy of the MediaDevices.getUserMedia(). Probably the NotAllowedError has been thrown.

Notes from documentation:

  1. Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
  2. A secure context is, in short, a page loaded using HTTPS or the file:/// URL scheme, or a page loaded from localhost.

 

References

  1. MediaDevices.getUserMedia() - Web APIs | MDN
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join