Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webview_flutter] iOS Camera Access Causes App Crash #163549

Open
Keddib opened this issue Feb 18, 2025 · 7 comments · May be fixed by flutter/packages#8766
Open

[webview_flutter] iOS Camera Access Causes App Crash #163549

Keddib opened this issue Feb 18, 2025 · 7 comments · May be fixed by flutter/packages#8766
Assignees
Labels
c: crash Stack traces logged to the console found in release: 3.29 Found to occur in 3.29 found in release: 3.30 Found to occur in 3.30 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: webview The WebView plugin P1 High-priority issues at the top of the work list package flutter/packages repository. See also p: labels. team-ios Owned by iOS platform team

Comments

@Keddib
Copy link

Keddib commented Feb 18, 2025

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!
@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Feb 19, 2025
@danagbemava-nc
Copy link
Member

Hi @Keddib, the url you have provided is not accessible. Please provide a publicly accessible url we can demo with. Also, do you have the camera permissions for iOS in your Info.plist file?

@danagbemava-nc danagbemava-nc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Feb 19, 2025
@Keddib
Copy link
Author

Keddib commented Feb 19, 2025

Actually I was running the demo app locally. I will update the link with this demo app. it's a simple react app that request access to camera. https://purple-technology.github.io/react-camera-pro/
Yes I've added these lines to my Info.plist

	<key>NSCameraUsageDescription</key>
	<string>Flutter requires acess to camera.</string>
	<key>NSMicrophoneUsageDescription</key>
	<string>Flutter requires acess to microphone.</string>

also added this to Podfile

    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',

        ## dart: PermissionGroup.camera
        'PERMISSION_CAMERA=1',

        ## dart: PermissionGroup.microphone
        'PERMISSION_MICROPHONE=1',
      ]

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Feb 19, 2025
@danagbemava-nc
Copy link
Member

Reproducible using the code sample provided in the original post above. I tested a native webview app and the camera worked as expected. Considering the error seems related to pigeon, the issue might be how we are communicating with the native side.

Tested on my iPhone XS running iOS 18.3.1

Labeling for further investigation

flutter doctor -v
[✓] Flutter (Channel stable, 3.29.0, on macOS 15.3 24D60 darwin-arm64, locale en-US) [2.7s]
    • Flutter version 3.29.0 on channel stable at /Users/deanli/dev/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 35c388afb5 (9 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.1) [3.8s]
    • Android SDK at /Users/deanli/Library/Android/sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: /Users/deanli/Applications/Android Studio Meerkat 2024.3.1 RC 1.app/Contents/jbr/Contents/Home/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2024.3) [10ms]
    • Android Studio at /Users/deanli/Applications/Android Studio Meerkat 2024.3.1 RC 1.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
    • android-studio-dir = /Users/deanli/Applications/Android Studio Meerkat 2024.3.1 RC 1.app
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)

[✓] Android Studio (version 2024.2) [8ms]
    • Android Studio at /Users/deanli/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.4+-12422083-b607.1)

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

[✓] Connected device (5 available) [14.1s]
    • Dean’s iPad (wireless) (mobile) • 00008103-000825C811E3401E • ios            • iOS 18.3.1 22D72
    • Nexus (wireless) (mobile)       • 00008020-001875E83A38002E • ios            • iOS 18.3.1 22D72
    • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 15.3 24D60 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 15.3 24D60 darwin-arm64
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 133.0.6943.126
    ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources [1,831ms]
    • All expected network resources are available.

• No issues found!
[!] Flutter (Channel master, 3.30.0-1.0.pre.236, on macOS 15.3 24D60 darwin-arm64, locale en-US) [5.7s]
    • Flutter version 3.30.0-1.0.pre.236 on channel master at /Users/deanli/dev/master
    ! Warning: `flutter` on your path resolves to /Users/deanli/dev/stable/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/deanli/dev/master. Consider adding /Users/deanli/dev/master/bin to the front of your path.
    ! Warning: `dart` on your path resolves to /Users/deanli/dev/stable/bin/dart, which is not inside your current Flutter SDK checkout at /Users/deanli/dev/master. Consider adding /Users/deanli/dev/master/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 19f23f2339 (2 hours ago), 2025-02-19 19:13:39 -0800
    • Engine revision 19f23f2339
    • Dart version 3.8.0 (build 3.8.0-116.0.dev)
    • DevTools version 2.43.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1) [2.3s]
    • Android SDK at /Users/deanli/Library/Android/sdk
    • Platform android-35, build-tools 35.0.1
    • Java binary at: /Users/deanli/Applications/Android Studio Meerkat 2024.3.1 RC 1.app/Contents/jbr/Contents/Home/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2024.3) [10ms]
    • Android Studio at /Users/deanli/Applications/Android Studio Meerkat 2024.3.1 RC 1.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
    • android-studio-dir = /Users/deanli/Applications/Android Studio Meerkat 2024.3.1 RC 1.app
    • Java version OpenJDK Runtime Environment (build 21.0.5+-12932927-b750.29)

[✓] Android Studio (version 2024.2) [9ms]
    • Android Studio at /Users/deanli/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.4+-12422083-b607.1)

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

[✓] Connected device (4 available) [7.8s]
    • Dean’s iPad (wireless) (mobile) • 00008103-000825C811E3401E • ios            • iOS 18.3.1 22D72
    • Nexus (wireless) (mobile)       • 00008020-001875E83A38002E • ios            • iOS 18.3.1 22D72
    • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 15.3 24D60 darwin-arm64
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 133.0.6943.126
    ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

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

! Doctor found issues in 1 category.

@danagbemava-nc danagbemava-nc added c: crash Stack traces logged to the console p: webview The WebView plugin package flutter/packages repository. See also p: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on fyi-ecosystem For the attention of Ecosystem team team-ios Owned by iOS platform team found in release: 3.29 Found to occur in 3.29 found in release: 3.30 Found to occur in 3.30 and removed in triage Presently being triaged by the triage team labels Feb 20, 2025
@zonanapo
Copy link

I have the same problem with the latest version of Flutter. IOS is crash when WebView works

@zonanapo
Copy link

The old Flutter works well, and the new Flutter seems to have an error

@gongdongho12
Copy link

gongdongho12 commented Feb 25, 2025

I have the same issue too.

I guess it happens when a certain module version is forced to change as the sdk version goes up.
It doesn't just release the sdk version, but it works only when you map it to the version that went back to normal in Podfile.lock.

I'll have to fix it and use it for now 😢

@stuartmorgan stuartmorgan changed the title iOS WebView Camera Access Causes App Crash While Android Works Fine [webview_flutter] iOS Camera Access Causes App Crash Feb 25, 2025
@stuartmorgan stuartmorgan added P1 High-priority issues at the top of the work list triaged-ecosystem Triaged by Ecosystem team labels Feb 25, 2025
@flutter-triage-bot flutter-triage-bot bot removed fyi-ecosystem For the attention of Ecosystem team triaged-ecosystem Triaged by Ecosystem team labels Feb 25, 2025
@gafsel

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: crash Stack traces logged to the console found in release: 3.29 Found to occur in 3.29 found in release: 3.30 Found to occur in 3.30 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: webview The WebView plugin P1 High-priority issues at the top of the work list package flutter/packages repository. See also p: labels. team-ios Owned by iOS platform team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants