Skip to content

[webview_flutter] iOS Camera Access Causes App Crash #163549

@Keddib

Description

@Keddib

What package does this bug report belong to?

webview_flutter

What target platforms are you seeing this bug on?

iOS

Have you already upgraded your packages?

Yes

Dependency versions

pubspec.lock
dependencies:
  permission_handler: ^11.3.1
  webview_flutter: ^4.10.0
  webview_flutter_android: ^4.3.2
  webview_flutter_wkwebview: ^3.18.1
  http: ^1.1.0

Steps to reproduce

1- Create a Flutter app and install webview_flutter
2- Configure WebView to load a url of a simple App that access camera (I used Vite React App with one page accessing camera after abutton click)
3 - load the app and try to access the camera
4 - the app crashes when attempting to access the camera on IOS
!! Both on Real device and simulator

Expected results

The web application should be able to access the camera on both iOS and Android platforms after permissions are granted, allowing for camera functionality within the WebView.

Actual results

On Android: Camera access works correctly
On iOS: App crashes when attempting to access the camera

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const MaterialApp(home: WebViewScreen()));
}

class WebViewScreen extends StatefulWidget {
  const WebViewScreen({super.key});

  @override
  State<WebViewScreen> createState() => _WebViewScreenState();
}

class _WebViewScreenState extends State<WebViewScreen> {
  late final WebViewController _controller;
  bool _isLoading = true;

  @override
  void initState() {
    super.initState();
    _setupWebView();
  }

  Future<void> _setupWebView() async {
    await Permission.camera.request();
    await Permission.microphone.request();
    late final PlatformWebViewControllerCreationParams params;

    if (WebViewPlatform.instance is WebKitWebViewPlatform) {
      params = WebKitWebViewControllerCreationParams(
        allowsInlineMediaPlayback: true,
        mediaTypesRequiringUserAction: const <PlaybackMediaTypes>{},
      );
    } else {
      params = const PlatformWebViewControllerCreationParams();
    }

    _controller = WebViewController.fromPlatformCreationParams(params);

    if (_controller.platform is WebKitWebViewController) {
      final WebKitWebViewController webKitController =
          _controller.platform as WebKitWebViewController;
      webKitController.setAllowsBackForwardNavigationGestures(true);
    }

    _controller.platform.setOnPlatformPermissionRequest((request) {
      debugPrint('Permission requested: ${request.types}');
      request.grant();
    });

    await _controller.setJavaScriptMode(JavaScriptMode.unrestricted);
    setState(() {
      _isLoading = false;
    });
    await _controller.loadRequest(Uri.parse('https://purple-technology.github.io/react-camera-pro/'));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body:
          _isLoading
              ? const Center(child: CircularProgressIndicator())
              : WebViewWidget(controller: _controller),
    );
  }
}

Screenshots or Videos

Screenshots / Video demonstration

[Upload media here]

Screen.Recording.2025-02-18.at.18.08.15.mov
Image

Logs

Logs: I see logs only on xcode
pigeonApi	webview_flutter_wkwebview.PigeonApiWKFrameInfo	0x0000600001785ac0
pigeonRegistrar	webview_flutter_wkwebview.ProxyAPIRegistrar	0x0000600002907720
webview_flutter_wkwebview.WebKitLibraryPigeonProxyApiRegistrar	webview_flutter_wkwebview.WebKitLibraryPigeonProxyApiRegistrar	
assetManager	webview_flutter_wkwebview.FlutterAssetManager	0x00006000000088a0
bundle	NSBundle	0x0000600002123200
pigeonDelegate	webview_flutter_wkwebview.FrameInfoProxyAPIDelegate	0x000060000002b5b0
pigeonInstance	WKFrameInfo	0x0000000110c09820
baseNSObject@0	NSObject	
self	webview_flutter_wkwebview.FrameInfoProxyAPIDelegate	0x000060000002b5b0

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.29.0, on macOS 15.3.1 24D70 darwin-arm64, locale en-MA) [1,298ms]
    • Flutter version 3.29.0 on channel stable at /opt/homebrew/Caskroom/flutter/3.27.4/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 35c388afb5 (8 days ago), 2025-02-10 12:48:41 -0800
    • Engine revision f73bfc4522
    • Dart version 3.7.0
    • DevTools version 2.42.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [2.2s]
    • Android SDK at /Users/keddib/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /Users/keddib/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2) [1,040ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [13ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2) [12ms]
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] VS Code (version 1.97.2) [11ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.104.0

[✓] Connected device (6 available) [6.4s]
    • sdk gphone64 arm64 (mobile)     • emulator-5554                        • android-arm64  • Android 15 (API 35) (emulator)
    • iPhone (mobile)                 • 00008110-000814492162401E            • ios            • iOS 18.1.1 22B91
    • iPhone 15 Pro Max (mobile)      • 3378509F-6CCD-445A-B42D-033245DC9D01 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   • macOS 15.3.1 24D70 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         • macOS 15.3.1 24D70 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript • Google Chrome 133.0.6943.98

[✓] Network resources [496ms]
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listc: crashStack traces logged to the consolefound in release: 3.29Found to occur in 3.29found in release: 3.30Found to occur in 3.30has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer versionteam-iosOwned by iOS platform team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions