Electron app not asking for Camera and Microphone permission on macOS Monterey
Asked Answered
Z

3

7

I have built an application of stack electron and reactjs. I am trying to access the camera and microphone from the application. But the app does not ask for permission when requested and also it does not show in the System Preferences -> Security and Privacy under camera and microphone. Below are the versions I am using:

"electron": "^15.3.0",
"electron-builder": "^22.14.5",
"electron-devtools-installer": "^3.2.0",
"electron-notarize": "^1.1.1",
"electron-rebuild": "^3.2.3", 
"react": "^17.0.2"

Let me know what I am missing or needs to be changed. Thanks in advance.

Zooid answered 27/4, 2022 at 6:9 Comment(0)
M
12

I also had this problem it worked fine in macOS Catalina but in Monterey sometimes it didn't.

I solved after reading this in the electron official documentation:

"If you plan to access the microphone or camera within your app using Electron's APIs, you'll also need to add the following entitlements"

<key>com.apple.security.device.audio-input</key>
<true/>
<key>com.apple.security.device.camera</key>
<true/>

To add the entitlements since you are using electron-builder there's a config that you can use in package.json to add it under "mac" you add this:

"extendInfo": {
        "NSMicrophoneUsageDescription": "Please give us access to your microphone",
        "NSCameraUsageDescription": "Please give us access to your camera",
        "com.apple.security.device.audio-input": true,
        "com.apple.security.device.camera": true
      },

And then you need to add the following lines to ask for media permissions:


const { systemPreferences } = require('electron')

const microphone = systemPreferences.askForMediaAccess('microphone');
const camera = systemPreferences.askForMediaAccess('camera');

Mikemikel answered 20/5, 2022 at 17:39 Comment(0)
S
5

I would like to add extra information with the answer of Caio Nakai I'm having application crash issue with this fix also.

So I found the following fix. Under mac configuration please add the following property as false

"hardenedRuntime": false
Seena answered 13/8, 2022 at 21:5 Comment(1)
Thanks for adding this information. I had the crash too before i used your fix.Size
I
2

Peace and Kindness! This helped me:

systemPreferences.askForMediaAccess('microphone') systemPreferences.askForMediaAccess('camera')

but only with it

https://www.electron.build/configuration/mas https://github.com/electron/osx-sign/blob/main/entitlements/default.darwin.plist

entitlements String | “undefined” - The path to entitlements file for signing the app. build/entitlements.mas.plist will be used if exists (it is a recommended way to set). See this folder in osx-sign’s repository for examples. Be aware that your app may crash if the right entitlements are not set like com.apple.security.cs.allow-jit for example on arm64 builds with Electron 20+. See Signing and Notarizing macOS Builds from the Electron documentation for more information.

Invade answered 6/6, 2023 at 9:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.