Skip to content

Lesson 9 of 9 · 23m

Permissions and Capability Detection in Production

The browser permission model is contextual, per-origin, and revocable — build capability ladders instead of assuming yes or no.

A browser permission is not a boolean you collect once and file away. It is a contextual grant, scoped to an origin, influenced by user gesture, browser policy, device support, embedded context, and sometimes enterprise configuration. Teams get this wrong when they design onboarding as a wall of prompts: camera, microphone, notifications, location — asked before the user has seen any value. The predictable result is permanent denial and a support ticket saying the product is broken.

Ask in context, not at boot

The correct moment to request microphone access is when the user presses "join audio," not during first page load. The prompt then explains itself through the interface around it. Before the request, show application-level copy about what will happen; after denial, show a recovery path because browsers may not prompt again.

async function joinAudio(button) {
  try {
    const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
    attachAudio(stream);
  } catch (error) {
    if (error.name === "NotAllowedError") showPermissionHelp("microphone");
    else if (error.name === "NotFoundError") showNoMicrophone();
    else reportJoinFailure(error);
  }
}

NotAllowedError means the user or policy said no. NotFoundError means there is no suitable device. NotReadableError can mean another application owns the device. Treat them as different support cases.

Permissions API: useful, incomplete

const status = await navigator.permissions.query({ name: "notifications" });
// "granted" | "denied" | "prompt"

The Permissions API can query some capabilities, but browser support and accepted permission names vary. geolocation, notifications, camera, and microphone are not a uniform matrix across browsers. Use it as an optimization when available, not as the sole source of truth. Feature-detect the API itself first.

Capability ladders beat browser sniffing

Do not ask what browser this is. Ask what it can do:

const canNotify = "Notification" in window && navigator.serviceWorker;
const canPersist = navigator.storage && navigator.storage.persist;
const canPickFiles = "showOpenFilePicker" in window;

Then design tiers: full experience, reduced experience, and unsupported path. A file editor might use writable handles where available, upload/download where not. A PWA might use push where granted and email fallback elsewhere. The platform is heterogeneous by design; progressive enhancement is operational reality, not nostalgia.

Permissions are revocable and temporal

Users can revoke grants from site settings. Some permissions decay or require visible indicators. If your app caches "granted" forever in localStorage, it will confidently route users into dead ends. Re-check at the moment of use, handle failure, and expose a reset/help path that tells users exactly which browser UI to open.

Field notes

  • Iframes and cross-origin embeds often need explicit allow attributes such as allow="camera; microphone".
  • Permission prompts are not a branding surface; browser UI is deliberately constrained.
  • Never punish denial. Provide the degraded path and remember the user's application-level choice separately from browser state.
  • Test the full matrix: first prompt, allow, deny, revoke in settings, private window, embedded iframe, and mobile webview.

Was this lesson helpful?

Sign in to rate