Neynar Documentation

Request Camera and Microphone Access

Request permission to access the device’s camera and microphone. This method triggers a permission dialog in the host app and stores the user’s preference so they won’t be asked again for the same mini app.

This is an experimental feature that stores camera and microphone permission settings per mini app. The stored preference ensures users aren’t repeatedly prompted for the same permissions. Check the features.cameraAndMicrophoneAccess flag in the SDK context to determine if permissions have been granted.

Platform Support

Platform Supported Notes
iOS Full support with domain-level permissions
Android Supported (see note below)
Web Not currently supported

On Android, camera and microphone permissions work slightly differently than iOS. Once permissions are granted to the host app, mini apps may have access without additional prompts. This is standard behavior for Android WebView permissions.

Camera and microphone access is not supported in web mini apps. The action will always reject on web platforms.

Usage

import { sdk } from '@farcaster/miniapp-sdk'

try {
  await sdk.actions.requestCameraAndMicrophoneAccess()
  console.log('Camera and microphone access granted')
  // You can now use camera and microphone in your mini app
} catch (error) {
  console.log('Camera and microphone access denied')
  // Handle the denial gracefully
}

Return Value

Returns a Promise<void> that:

Feature Detection

Before using this action, check if it’s supported:

import { sdk } from '@farcaster/miniapp-sdk'

// Check if the feature is available
if (sdk.context.features?.cameraAndMicrophoneAccess) {
  // Feature is supported and permissions have been granted
  // You can use camera/microphone features
} else {
  // Feature is not supported or permissions not granted
}

Permissions

Example: Video Recording

import { sdk } from '@farcaster/miniapp-sdk'

async function startVideoRecording() {
  try {
    // Request permissions first
    await sdk.actions.requestCameraAndMicrophoneAccess()

// Now you can access getUserMedia
    const stream = await navigator.mediaDevices.getUserMedia({
      video: true,
      audio: true
    })

// Use the stream for video recording
    const videoElement = document.querySelector('video')
    if (videoElement) {
      videoElement.srcObject = stream
    }
  } catch (error) {
    if (error instanceof Error && error.name === 'NotAllowedError') {
      // Permissions were denied
      alert('Camera and microphone access is required for video recording')
    } else {
      console.error('Failed to start recording:', error)
    }
  }
}