Fix guide · Microphone test
How to fix "SecurityError" and "navigator.mediaDevices is undefined"
Browsers only allow microphone and camera access on secure pages. If the address starts with http:// instead of https://, or the page sits in a frame without permission, the browser either throws SecurityError or hides navigator.mediaDevices completely, which produces "TypeError: Cannot read properties of undefined (reading getUserMedia)". The fix is to use a secure address.
Quick fix checklist
- 1Check the address bar. The page should start with https:// or be localhost.
- 2Change http:// to https:// in the address, or reopen the site from a secure link.
- 3If you are in an app or embedded view, open the page in a normal browser tab.
- 4Allow the microphone and camera for the site, then reload and press Check again.
- 5If you run the site yourself, install a certificate and redirect all http traffic to https.
Why browsers require a secure context
The microphone and camera are sensitive. Browsers expose them only in a secure context so that an attacker on a shared network cannot swap the page and spy on you. Plain http pages, local network addresses such as 192.168.x.x and many in-app views do not qualify, even though localhost does.
A permissions policy can also block the device for a page inside a frame. The hosting page must allow microphone and camera for the frame.
Developer checklist
Serve over HTTPS with a valid certificate, test local work on localhost, and check window.isSecureContext before calling getUserMedia. For embeds, set allow="microphone; camera" on the iframe and avoid sandboxes that remove the permission. The microphone test is served over HTTPS so you can compare.
FAQ
Common questions
Why is navigator.mediaDevices undefined?
The page is not in a secure context, so the browser hides the media API. Open it over HTTPS or on localhost.
Does localhost count as secure?
Yes. Browsers treat localhost as secure, so you can develop without a certificate. Other local addresses need HTTPS.
What is a SecurityError in getUserMedia?
The browser refused because the page is insecure, was loaded in a restricted frame, or a policy forbids the device.
Is my data safe on an http page?
Avoid using the microphone and camera on http pages. Use https so the page cannot be altered in transit.