Handle camera permission denial
The browser camera prompt can be denied, dismissed, or blocked by site permissions. The session surfaces this as a CaptureError. Treat it as a UX state, not an exception.
Full example
import { CaptureError } from '@sladeid/slade-id-sdk';
try {
await session.start();
} catch (err) {
if (err instanceof CaptureError && err.code === 'CAMERA_PERMISSION_DENIED') {
showPermissionPrompt();
return;
}
throw err;
}
function showPermissionPrompt(): void {
// Your UI: explain that camera access is required and link to browser settings.
}What can go wrong
- The user dismissed the prompt without choosing. Subsequent
start()calls re-prompt on most browsers. On Safari, the user may need to clear site permissions. - The camera is in use by another tab or application. The session emits a different error code; check
err.coderather than assuming it is always permission-related. - No camera is available at all. The session throws
CaptureErrorwith codeNO_CAMERA. Surface a different message than permission-denied.