# Console: NotAllowedError: Permission denied (getUserMedia — camera or microphone blocked)

**Code:** `NotAllowedError: Permission denied` · **Category:** Browser · **Seen on:** Chrome, Firefox, Safari, JavaScript

The user (or the browser/OS/policy) denied camera or microphone access, so `navigator.mediaDevices.getUserMedia()` was rejected.

## Meaning

Permission can be denied at several layers: the site permission in the browser, the OS privacy setting for the browser, a `Permissions-Policy` header, or an iframe lacking the `allow="camera; microphone"` attribute. Reset the site permission and request it again after a user gesture.

## Common causes

- User clicked Block or dismissed the prompt
- Site permission set to Block in the browser
- OS-level camera/mic privacy blocks the browser (Windows, macOS)
- Iframe without `allow="camera; microphone"` or restrictive `Permissions-Policy`
- Not a secure context (HTTP)

## Quick fix

1. Click the lock icon → Site settings → Camera/Microphone → Allow, then reload
2. Allow the browser in the OS privacy settings
3. Serve over HTTPS and add `allow="camera; microphone"` to iframes

## Detailed fix by platform

### JavaScript

1. `try { const s = await navigator.mediaDevices.getUserMedia({ video: true, audio: true }); } catch (e) { console.log(e.name, e.message); }` — check `e.name`

### Windows

1. Settings → Privacy & security → Camera / Microphone → allow desktop apps and the browser

### macOS

1. System Settings → Privacy & Security → Camera / Microphone → enable the browser

## Code examples

### Ask after a click and handle each failure

```javascript
button.onclick = async () => {
  try {
    const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
    video.srcObject = stream;
  } catch (e) {
    // NotAllowedError (blocked), NotFoundError (no device), NotReadableError (in use)
    showHelp(e.name);
  }
};
```

## How to diagnose

1. **Name** — Exact e.name?
2. **Layers** — Browser, OS or iframe policy?
3. **Context** — HTTPS?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/browser/getusermedia-notallowederror)
