Skip to content

iOS app CRASH when using windowId in InAppWebView #2600

@MartinAKovachev

Description

@MartinAKovachev

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

@pichillilorenzo
@AlexV525
@crazecoder
@cbodin

We are receiving this error in the iOS simulator reports, when trying to push a page with an InAppWebView on top of another page with InAppWebView by passing the windowId from onCreateWindow callback:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region.  Bytes before following region: 4370350080
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      1047e4000-1047e8000    [   16K] r-x/r-x SM=COW  /Users/USER/Library/Developer/CoreSimulator/Devices/CFCFA94A-B021-4B65-AD60-835A2BC247GT/data/Containers/Bundle/Application/4887C6DF-B82E-42BA-9AF1-83B6477F6YTS/Runner.app/Runner
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [4908]

Triggered by Thread:  0

Kernel Triage:
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   ???                           	               0x0 ???
1   flutter_inappwebview_ios      	       0x104f48b3c specialized InAppWebView.observeValue(forKeyPath:of:change:context:) + 132 (InAppWebView.swift:714)
2   flutter_inappwebview_ios      	       0x104f2be64 InAppWebView.observeValue(forKeyPath:of:change:context:) + 20 [inlined]
3   flutter_inappwebview_ios      	       0x104f2be64 @objc InAppWebView.observeValue(forKeyPath:of:change:context:) + 256 (/<compiler-generated>:711)
4   Foundation                    	       0x180eb3200 NSKeyValueNotifyObserver + 248
5   Foundation                    	       0x180eb61e0 NSKeyValueDidChange + 380
6   Foundation                    	       0x180eb276c NSKeyValueDidChangeWithPerThreadPendingNotifications + 144
7   WebKit                        	       0x18c728a1c WebKit::NavigationState::didChangeEstimatedProgress() + 36
8   WebKit                        	       0x18ca2cfa4 WebKit::PageLoadState::callObserverCallback(void (WebKit::PageLoadStateObserverBase::*)()) + 760
9   WebKit                        	       0x18ca2ca3c WebKit::PageLoadState::commitChanges() + 916
10  WebKit                        	       0x18ca7dc04 WebKit::WebPageProxy::didStartProgress() + 136
11  WebKit                        	       0x18c5e7518 WebKit::WebPageProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 2652
12  WebKit                        	       0x18d03a238 IPC::MessageReceiverMap::dispatchMessage(IPC::Connection&, IPC::Decoder&) + 260
13  WebKit                        	       0x18caed9b4 WebKit::WebProcessProxy::dispatchMessage(IPC::Connection&, IPC::Decoder&) + 36
14  WebKit                        	       0x18c62206c WebKit::WebProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 1460
15  WebKit                        	       0x18d0286f4 IPC::Connection::dispatchMessage(WTF::UniqueRef<IPC::Decoder>) + 724
16  WebKit                        	       0x18d028b3c IPC::Connection::dispatchIncomingMessages() + 492
17  JavaScriptCore                	       0x19815a9f0 WTF::RunLoop::performWork() + 444
18  JavaScriptCore                	       0x19815b624 WTF::RunLoop::performWork(void*) + 32
19  CoreFoundation                	       0x1804284b8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
20  CoreFoundation                	       0x180428400 __CFRunLoopDoSource0 + 168
21  CoreFoundation                	       0x180427b88 __CFRunLoopDoSources0 + 220
22  CoreFoundation                	       0x180422584 __CFRunLoopRun + 780
23  CoreFoundation                	       0x180421e3c CFRunLoopRunSpecific + 536
24  GraphicsServices              	       0x190f62d00 GSEventRunModal + 164
25  UIKitCore                     	       0x185bcec98 -[UIApplication _run] + 796
26  UIKitCore                     	       0x185bd3064 UIApplicationMain + 124
27  UIKitCore                     	       0x184f9ad6c 0x184d72000 + 2264428
28  Runner.debug.dylib            	       0x104819ea4 static UIApplicationDelegate.main() + 128
29  Runner.debug.dylib            	       0x104819e14 static AppDelegate.$main() + 44
30  Runner.debug.dylib            	       0x104819f20 __debug_main_executable_dylib_entry_point + 28
31  ???                           	       0x1049353d8 ???
32  dyld                          	       0x104b92b4c start + 6000

The Flutter application crashes and closes the application.

Simulator:
Iphone 16 Pro Simulator iOS 18.4

Xcode version:
16.3

MacOS version:
15.4

flutter_inappwebview version:
^6.1.5

Flutter version:
3.29.0

Dart version:
3.7.0

Expected Behavior

The Flutter application doesn't crash and shows the content of the page when being pushed.

Steps with code example to reproduce

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';

class WebViewTab extends StatefulWidget {
  const WebViewTab({super.key, this.initialUrl, this.windowId})
    : assert(
        (initialUrl == null) != (windowId == null),
        'Either [initialUrl] or [windowId] should be set, but not both',
      );

  final String? initialUrl;
  final int? windowId;

  @override
  State<WebViewTab> createState() => _WebViewTabState();
}

class _WebViewTabState extends State<WebViewTab> {
  InAppWebViewController? _webViewController;
  bool _isLoading = true;
  bool _hasError = false;

  static const String _keyPrefix = 'web_view_tab_';

  @override
  void dispose() {
    _webViewController?.dispose();
    _webViewController = null;
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        InAppWebView(
          key: ValueKey('$_keyPrefix${widget.windowId ?? 'root'}'),
          initialSettings: InAppWebViewSettings(
            isInspectable: kDebugMode,
            javaScriptCanOpenWindowsAutomatically: true,
            supportMultipleWindows: true,
            supportZoom: false,
            allowsLinkPreview: false,
            disableLongPressContextMenuOnLinks: true,
          ),
          windowId: widget.windowId,
          initialUrlRequest:
              widget.initialUrl != null
                  ? URLRequest(url: WebUri(widget.initialUrl!))
                  : null,
          onWebViewCreated: _handleWebViewCreated,
          onLoadStop: _handleLoadStop,
          onReceivedError: _handleReceivedError,
          onCreateWindow: (_, action) => _handleCreateWindow(context, action),
          onCloseWindow: (_) => _handleCloseWindow(context),
        ),
        if (_isLoading) const CircularProgressIndicator(),
      ],
    );
  }

  void _handleWebViewCreated(InAppWebViewController controller) {
    _webViewController = controller;
  }

  void _handleLoadStop(InAppWebViewController _, WebUri? _) {
    setState(() => _isLoading = false);
  }

  void _handleReceivedError(
    InAppWebViewController _,
    WebResourceRequest _,
    WebResourceError _,
  ) {
    setState(() {
      _isLoading = false;
      _hasError = true;
    });
  }

  Future<dynamic>? _evaluateJavascript(String code) {
    return _webViewController?.evaluateJavascript(source: code);
  }

  Future<bool> _handleCreateWindow(
    BuildContext context,
    CreateWindowAction action,
  ) async {
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (_) => WebViewTab(windowId: action.windowId),
      ),
    );
    return true;
  }

  void _handleCloseWindow(BuildContext context) {
    Navigator.of(context).maybePop();
  }
}

Stacktrace/Logs

Stacktrace/Logs
Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region.  Bytes before following region: 4370350080
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      1047e4000-1047e8000    [   16K] r-x/r-x SM=COW  /Users/USER/Library/Developer/CoreSimulator/Devices/CFCFA94A-B021-4B65-AD60-835A2BC247GT/data/Containers/Bundle/Application/4887C6DF-B82E-42BA-9AF1-83B6477F6YTS/Runner.app/Runner
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [4908]

Triggered by Thread:  0

Kernel Triage:
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter
VM - (arg = 0x3) mach_vm_allocate_kernel failed within call to vm_map_enter


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   ???                           	               0x0 ???
1   flutter_inappwebview_ios      	       0x104f48b3c specialized InAppWebView.observeValue(forKeyPath:of:change:context:) + 132 (InAppWebView.swift:714)
2   flutter_inappwebview_ios      	       0x104f2be64 InAppWebView.observeValue(forKeyPath:of:change:context:) + 20 [inlined]
3   flutter_inappwebview_ios      	       0x104f2be64 @objc InAppWebView.observeValue(forKeyPath:of:change:context:) + 256 (/<compiler-generated>:711)
4   Foundation                    	       0x180eb3200 NSKeyValueNotifyObserver + 248
5   Foundation                    	       0x180eb61e0 NSKeyValueDidChange + 380
6   Foundation                    	       0x180eb276c NSKeyValueDidChangeWithPerThreadPendingNotifications + 144
7   WebKit                        	       0x18c728a1c WebKit::NavigationState::didChangeEstimatedProgress() + 36
8   WebKit                        	       0x18ca2cfa4 WebKit::PageLoadState::callObserverCallback(void (WebKit::PageLoadStateObserverBase::*)()) + 760
9   WebKit                        	       0x18ca2ca3c WebKit::PageLoadState::commitChanges() + 916
10  WebKit                        	       0x18ca7dc04 WebKit::WebPageProxy::didStartProgress() + 136
11  WebKit                        	       0x18c5e7518 WebKit::WebPageProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 2652
12  WebKit                        	       0x18d03a238 IPC::MessageReceiverMap::dispatchMessage(IPC::Connection&, IPC::Decoder&) + 260
13  WebKit                        	       0x18caed9b4 WebKit::WebProcessProxy::dispatchMessage(IPC::Connection&, IPC::Decoder&) + 36
14  WebKit                        	       0x18c62206c WebKit::WebProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 1460
15  WebKit                        	       0x18d0286f4 IPC::Connection::dispatchMessage(WTF::UniqueRef<IPC::Decoder>) + 724
16  WebKit                        	       0x18d028b3c IPC::Connection::dispatchIncomingMessages() + 492
17  JavaScriptCore                	       0x19815a9f0 WTF::RunLoop::performWork() + 444
18  JavaScriptCore                	       0x19815b624 WTF::RunLoop::performWork(void*) + 32
19  CoreFoundation                	       0x1804284b8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
20  CoreFoundation                	       0x180428400 __CFRunLoopDoSource0 + 168
21  CoreFoundation                	       0x180427b88 __CFRunLoopDoSources0 + 220
22  CoreFoundation                	       0x180422584 __CFRunLoopRun + 780
23  CoreFoundation                	       0x180421e3c CFRunLoopRunSpecific + 536
24  GraphicsServices              	       0x190f62d00 GSEventRunModal + 164
25  UIKitCore                     	       0x185bcec98 -[UIApplication _run] + 796
26  UIKitCore                     	       0x185bd3064 UIApplicationMain + 124
27  UIKitCore                     	       0x184f9ad6c 0x184d72000 + 2264428
28  Runner.debug.dylib            	       0x104819ea4 static UIApplicationDelegate.main() + 128
29  Runner.debug.dylib            	       0x104819e14 static AppDelegate.$main() + 44
30  Runner.debug.dylib            	       0x104819f20 __debug_main_executable_dylib_entry_point + 28
31  ???                           	       0x1049353d8 ???
32  dyld                          	       0x104b92b4c start + 6000

Flutter version

v3.29.0

Operating System, Device-specific and/or Tool

Iphone 16 Pro iOS 18.4
Xcode 16.3

Plugin version

^6.1.5

Additional information

No response

Self grab

  • I'm ready to work on this issue!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions