Tondavo

Camera or microphone not working on a phone

getUserMedia on iPhone, Android and in-app browsers. Updated

The most common cause during development is the address: browsers expose the camera and microphone only in a secure context, meaning HTTPS or localhost. Open your dev server on the phone at http://192.168.x.x and navigator.mediaDevices is undefined. After that, check the permission state, and whether the page is running inside another app's browser.

In Safari the error reads undefined is not an object (evaluating 'navigator.mediaDevices.getUserMedia'); in Chrome, Cannot read properties of undefined (reading 'getUserMedia'). Both mean the page isn't a secure context. Check with:

console.log(window.isSecureContext); // false on http://192.168.x.x

WebKit (every iPhone browser) and Chrome both hide mediaDevices and crypto.subtle outside a secure context, so the same page works on your computer at localhost and breaks on the phone. Fix it by giving the phone HTTPS: see how to open localhost on your phone.

The error names, and what usually causes them on a phone

ErrorUsual cause on mobile
TypeErrormediaDevices undefined (not a secure context), or empty constraints
NotAllowedErrorThe user tapped Don't Allow, Safari's site setting or the iOS-wide setting is Deny, the host app has no camera or microphone permission, or a Permissions Policy blocks it
NotReadableErrorPermission granted, but another app, tab or call is using the camera
OverconstrainedErrorAn exact constraint the phone can't meet, such as a deviceId from another device or a resolution it doesn't have
NotFoundErrorNo matching device; rare on phones, more common in web views that expose none

iPhone specifics

  • Prompts come back. Safari often asks again after a reload or after the screen turns off. This is an open WebKit issue (bug 280394). Home Screen web apps don't inherit Safari's per-site choice. Ask at the moment the user starts the feature, not on page load.
  • Settings. Camera and Microphone can be set to Ask, Deny or Allow for all sites in Safari's settings, and per site from the address bar's page menu. A Deny there produces NotAllowedError with no prompt.
  • Video needs playsinline. Without it, iPhone plays the camera preview full screen. Add muted if it should start on its own.
  • Sound still needs a tap. Granting the camera isn't reliably treated as a tap for audio. Start or resume an AudioContext from a tap.

In-app browsers (Instagram, Facebook, TikTok, LinkedIn)

Links opened inside these apps load in the app's own web view, not in Safari or Chrome, and the app decides what the page may use:

  • iOS: web views support getUserMedia since iOS 14.3, but only when the host app has camera or microphone permission (its NSCameraUsageDescription and NSMicrophoneUsageDescription). The app can also answer the page's request itself.
  • Android: a WebView denies camera and microphone unless the host app grants them in WebChromeClient.onPermissionRequest.
  • Iframes need allow="camera; microphone", or the user is never asked.

Each app handles this differently and changes over time, so don't rely on it. Catch the error and offer an "Open in Safari" or "Open in Chrome" link. Then test in the apps your users actually come from.

Test it on the real phone

Desktop Chrome at iPhone size has a different engine, different permission prompts and no in-app browsers. Tondavo opens your dev server on your own phone over HTTPS from a QR code, so getUserMedia is available. The permission prompt itself still needs your tap. Tondavo is tested on iPhone Safari; Android and in-app browsers are untested.

To try it: npx tondavo. See Getting started.

Sources