Skip to content

requestCameraAndMicrophoneAccess

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.

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:

  • Resolves when the user grants permission
  • Rejects when the user denies permission or dismisses the dialog

Feature Detection

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

import { sdk } from '@farcaster/miniapp-sdk'
 
// Check if the feature is available
const context = await sdk.context
if (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

  • The permission dialog will only be shown once per mini app - the user's choice is stored
  • If the user has previously granted or denied permissions, the stored preference is used and the promise will immediately resolve or reject without showing a dialog
  • The stored permissions ensure users aren't repeatedly asked for the same access
  • Users can revoke permissions at any time by:
    1. Opening the mini app
    2. Tapping the options menu (three dots)
    3. Toggling the camera and microphone access switch

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)
    }
  }
}

Platform Support

PlatformSupportedNotes
iOSFull support with domain-level permissions
AndroidSupported (see note below)
WebNot currently supported