Skip to main content
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

PlatformSupportedNotes
iOSFull support with domain-level permissions
AndroidSupported (see note below)
WebNot 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:
  • 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
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

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