You could try something like the following, however it would need to check in tick
since there’s no way to listen for the permission granted as far as I know.
async function onCameraPermissionGranted(onGranted) {
if (!navigator.permissions) return;
try {
const status = await navigator.permissions.query({ name: 'camera' });
if (status.state === 'granted') onGranted();
status.onchange = () => {
if (status.state === 'granted') onGranted();
};
} catch (err) {
console.error('Could not query camera permission:', err);
}
}
onCameraPermissionGranted(() => {
console.log('Camera permission is granted – go ahead and use the camera!');
});