React Native WebView Integration Guide
Overview
This React Native WebView integration provides a solution for the microphone access challenge faced by Revrag’s embed agent when implemented in mobile apps using WebView. The embed agent requires microphone access to enable voice-based AI assistance for website navigation, but traditional WebView implementations often fail to properly delegate microphone permissions to the embedded website.Problem Statement
Revrag’s embed agent is a JavaScript SDK that can be integrated into any website to provide AI-powered voice assistance. However, when mobile apps load websites containing the embed agent in a WebView, the microphone access required by the agent is often blocked or not properly delegated, preventing users from interacting with the AI assistant.Prerequisites
- React Native 0.72+
- iOS 13+ / Android API 21+
- Microphone permissions on target device
This integration requires proper setup of WebView microphone permissions and real-time audio communication capabilities.
Installation
Install the required packages using your preferred package manager:iOS Pod Installation
For iOS, run pod install after installing dependencies:Solution Overview
This project implements a React Native WebView solution using thereact-native-webview package with proper microphone permission handling.
The solution:
- Requests native microphone permissions using the
react-native-permissionspackage - Delegates permissions to the WebView when the embed agent requests microphone access
- Handles permission states across both native and WebView contexts
- Provides a seamless user experience for voice interactions
Key Features
- ✅ Native Microphone Permission Handling: Properly requests and manages microphone permissions at the app level
- ✅ WebView Permission Delegation: Seamlessly delegates permissions to the embedded website
- ✅ Cross-Platform Support: Works on both Android and iOS
- ✅ Error Handling: Comprehensive error handling and user feedback
- ✅ Configurable: Easy configuration for different websites and use cases
Android Configuration
1. Android Manifest Permissions
Add the following permissions to yourandroid/app/src/main/AndroidManifest.xml:
Permission Purposes:
RECORD_AUDIO: Grants permission to record audio from microphoneMODIFY_AUDIO_SETTINGS: Allows modification of audio settingsINTERNET: Required for WebView to load web contentACCESS_NETWORK_STATE: Required for network connectivity checks
2. Android MainActivity Configuration
Update yourandroid/app/src/main/java/com/yourapp/MainActivity.kt:
Key Configuration Features:
- JavaScript Enabled: Allows web content to execute JavaScript code
- Media Playback: Disables user gesture requirement for media playback
- Permission Handler: Automatically grants microphone and camera permissions
iOS Configuration
1. iOS Permissions
CRITICAL: Add the following permissions to your
ios/YourAppName/Info.plist. Missing NSMicrophoneUsageDescription will cause the app to crash when accessing the microphone.WebView Implementation
Permission Request Handling
WebView Configuration
JavaScript Injection for Testing
Platform-Specific Configuration
Android
The Android configuration includes native WebView settings and permission handling as shown above.iOS
Add the microphone usage description toios/YourApp/Info.plist:
Permission Flow
- App Launch: Android system checks for declared permissions
- Runtime Request: React Native requests microphone permission from user
- WebView Permission: WebView automatically grants microphone access to web content
- Web Content Access: JavaScript can access microphone via
navigator.mediaDevices.getUserMedia()
Testing
1. Test HTML Files
Create test files inandroid/app/src/main/assets/ for local testing:
test-microphone.html:
2. Manual Testing Steps
- Launch the app and navigate to the WebView screen
- Check console logs for permission status
- Verify microphone access in web content
- Test audio recording functionality
3. Debug Information
- Console logs show permission request status
- WebView error handling for failed loads
- JavaScript console messages are captured
Integration with Revrag Embed Agent
To integrate this solution with Revrag’s embed agent:- Deploy the embed agent on your target website
- Update the WebView source URL to point to your website
- Test microphone access by triggering the embed agent’s voice functionality
Troubleshooting
Common Issues
Permission Denied
Permission Denied
Check the following requirements:
- ✅ Android manifest permissions declared
- ✅ Runtime permission requests implemented
- ✅ WebView permission handling configured
- ✅ App permissions granted in device settings
WebView Not Loading
WebView Not Loading
Verify connectivity and configuration:
- ✅ Check internet connectivity
- ✅ Verify URL accessibility in browser
- ✅ Check WebView configuration settings
- ✅ Ensure JavaScript is enabled
Microphone Not Working in WebView
Microphone Not Working in WebView
Debug microphone access issues:
- ✅ Verify device microphone functionality
- ✅ Check app permissions in device settings
- ✅ Ensure WebView JavaScript is enabled
- ✅ Test with microphone test HTML
Debug Steps
- Check the console logs for permission status
- Verify native permissions are granted
- Test WebView microphone access using test HTML files
- Ensure the target website supports microphone access
Best Practices
Security & Permissions:
- Only grant necessary permissions to WebView
- Restrict WebView to trusted domains using origin whitelist
- Always request user permission before accessing microphone
- Ensure audio data is handled securely and privately
Performance Optimization:
- Load WebView only when needed (lazy loading)
- Cache permission status to avoid repeated requests
- Implement graceful fallbacks for permission denials
- Properly dispose of WebView resources to prevent memory leaks
Configuration Management:
- Use environment variables for sensitive information
- Create reusable configuration objects
- Test with different target URLs during development
- Monitor WebView performance and error rates
Usage Examples
Complete Implementation Example
Support
For additional help:- Email Support: contact@revrag.ai
Last Updated: June 2025