logo
On this page

Running electron applications on macOS Monterey (12.2.1) and above versions causes camera and other devices to not work or crash?

2023-03-31
Products / Plugins:Video Call / Audio Call
Platform / Framework:Electron

This is because macOS Monterey (12.2.1) and above versions require actively setting permissions for these devices. Please add the following handling in the electron main process code:

const {systemPreferences} = require('electron')
async function checkDeviceAccessPrivilege()
{
    const cameraAccessPrivilege = systemPreferences.getMediaAccessStatus('camera');
    console.log(
        `checkDeviceAccessPrivilege before apply cameraAccessPrivilege: ${cameraAccessPrivilege}`
    );
    if (cameraAccessPrivilege !== 'granted') {
        await systemPreferences.askForMediaAccess('camera');
    }
    const micAccessPrivilege = systemPreferences.getMediaAccessStatus('microphone');
    console.log(
        `checkDeviceAccessPrivilege before apply micAccessPrivilege: ${micAccessPrivilege}`
    );
    if (micAccessPrivilege !== 'granted') {
        await systemPreferences.askForMediaAccess('microphone');
    }
    const screenAccessPrivilege = systemPreferences.getMediaAccessStatus('screen');
    console.log(
        `checkDeviceAccessPrivilege before apply screenAccessPrivilege: ${screenAccessPrivilege}`
    );
}

if(process.platform == 'darwin')
{
    checkDeviceAccessPrivilege()
}

Previous

What is the correspondence between Qt's enumerated windows and the window enumeration in the SDK?

Next

Why is the font display inconsistent across multiple platforms after some files are transcoded?