NotAllowedError: getUserMedia() is not allowed — how do I fix camera or microphone access?

A rejected getUserMedia() call can report NotAllowedError when access is denied or the frame lacks the required permission. First check whether navigator.mediaDevices is available. In an insecure context, the API can be absent entirely, so calling it can fail before a camera permission request is made.
Explain what the device is for and request access as part of the feature the user chooses to start. Handle rejection so the interface can distinguish a denied request from one that never had access in that context. Keep the denial visible without immediately prompting again.
Request access from the frame and origin where users will run the feature. Test an allowed request, a user denial and a frame without camera delegation separately. The caller should handle both an unavailable API and a rejection from the API.
async function startCamera() { if (!window.isSecureContext || !navigator.mediaDevices?.getUserMedia) { return { error: 'Camera API is unavailable in this context' }; } try { return { stream: await navigator.mediaDevices.getUserMedia({ video: true }) }; } catch (error) { return { error: error.name }; } }
Check the page’s secure context, camera permission indicator and iframe allow policy before testing another request from a button.