expo-camera does not work on web

I tried implementing expo-camera on a web application, but it returns:

CameraManager.requestPermissionsAsync is not a function

I also tried to preview the snack on the expo-camera docs, and there is the same error.

I’m not sure it’s the “right” way to do this, but I did the following:

if (Platform.OS.toLowerCase() === "web") {
  setHasPermission(true);
} else {
  const { status } = await BarCodeScanner?.requestPermissionsAsync();
  setHasPermission(status === "granted");
}

Actually, I found the right way to do this. For the web, you need to uses the Permissions module.

Something like this:

const [permission, askPermission] = Permissions.usePermissions(
    Permissions.CAMERA,
  );
...

useEffect(() => {
  if (permission?.permissions?.camera?.granted) {
    setShowBarCodeScanner(true);
  } else {
    askPermission();
  }
}, [permission?.permissions?.camera, setShowBarCodeScanner, askPermission]);

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.