2

I have a web electron application and I want to implement camera in one of the pages.

The problem is that lately for security reasons webcam can only be accessed via 'https'. But in case of an Electron app where the application is served locally the scheme is different and therefore streaming fails. So my question is:

Is there any good solution to implement webcam inside electron?

If not, what solution other than webcam might work?

Herbi Shtini
  • 2,002
  • 29
  • 34
  • When I [search](https://duckduckgo.com/?q=electron+camera&ia=web) for "electron camera," I get a lot of relevant results. ([This](https://ourcodeworld.com/articles/read/134/how-to-use-the-camera-with-electron-framework-create-a-snapshot-and-save-the-image-on-the-system) and [this](https://github.com/hokein/electron-sample-apps/tree/master/camera) are in the first five, for instance.) Did they not show up in your searching? Or was there some problem applying what they demonstrate? – T.J. Crowder Mar 07 '19 at 14:02
  • @T.J.Crowder No actually I have seen a lot of them(both your links) but as I have mentioned the required secure connection has been introduced lately. It will work fine in development(localhost) but not on production and that is because of the protocol – Herbi Shtini Mar 07 '19 at 14:05
  • If you're saying it used to work and now it doesn't because of a new requirement for HTTPS, I don't see [a bug](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+camera) for that unless it's [this one](https://github.com/electron/electron/issues/12010). If so, it's an open bug, not sure you'll be able to do much until it's fixed. – T.J. Crowder Mar 07 '19 at 14:16
  • @T.J.Crowder actually I tested it and it will work with 'file' scheme but we have configured a custom scheme and with that is not working not sure what is missing though – Herbi Shtini Mar 07 '19 at 14:19

1 Answers1

4

I am answering my own question in case it helps anyone else. In my case a had a custom scheme instead of the standard one which is file but I was missing something. I found out I just had to add: { secure: true } inside registerStandardSchemes(version 4). That makes electron know that this scheme is secure and that is enough for webcam to work.

Look through electron documentation for more help

Herbi Shtini
  • 2,002
  • 29
  • 34
  • can you share some code how make it work for the camera please? im having same issue, cant figure out what to do – Juliver Galleto Jul 22 '21 at 09:53
  • @JuliverGalleto I guess it was lately changed to 'registerSchemesAsPrivileged'. You have to set `protocol.registerSchemesAsPrivileged([{scheme: 'YOUR_SCHEME', privileges: {standard: true, secure: true}} ])`. Hope that helps. – Herbi Shtini Jul 23 '21 at 15:34
  • thank you for your response, in my case, I'm working on it on a raspberry pi device, it can't find the camera module so I decided to move to python thing instead. – Juliver Galleto Jul 23 '21 at 17:14