Flutter WebView Integration Guide
Overview
This Flutter 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
- Flutter 3.0+
- 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. Check out the detailed documentation for flutter_inappwebview.
Installation
Add the required packages to yourpubspec.yaml:
Solution Overview
This project implements a Flutter WebView solution using theflutter_inappwebview package with proper microphone permission handling.
The solution:
- Requests native microphone permissions using the
permission_handlerpackage - 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:
iOS Configuration
1. iOS Permissions
CRITICAL: Add the following permissions to your
ios/Runner/Info.plist. Missing NSMicrophoneUsageDescription will cause the app to crash when accessing the microphone.WebView Implementation
Permission Handling
The app uses a two-layer permission system:WebView Configuration
The WebView is configured with specific settings to enable microphone access:Usage Examples
Complete Implementation Example
Troubleshooting
Common Issues
Microphone permission denied
Microphone permission denied
Check the following requirements:
- ✅ App has microphone permissions in device settings
- ✅ Manifest permissions are declared correctly
- ✅ Permission handler is implemented properly
- ✅ WebView permission delegation is configured
WebView not loading
WebView not loading
Verify connectivity and configuration:
- ✅ Check internet connectivity
- ✅ Verify URL accessibility in browser
- ✅ Ensure JavaScript is enabled
- ✅ Check mixed content settings
JavaScript errors in WebView
JavaScript errors in WebView
Debug JavaScript execution issues:
- ✅ Verify JavaScript is enabled in WebView settings
- ✅ Check console messages for errors
- ✅ Test website in mobile browser first
- ✅ Ensure all required permissions are granted
Best Practices
Security & Permissions:
- Only grant necessary permissions to WebView
- Restrict WebView to trusted domains
- Always request user permission before accessing microphone
- Handle permission denials gracefully with user-friendly messages
Performance Optimization:
- Use lazy loading for WebView when possible
- Cache permission status to avoid repeated requests
- Implement proper error handling and loading states
- Monitor WebView memory usage and dispose properly
Configuration Management:
- Use environment variables for sensitive URLs
- Create configurable settings for different environments
- Test with various target websites during development
- Implement logging for debugging and monitoring
Support
For additional help:- Email Support: contact@revrag.ai
Last Updated: June 2025