Skip to content

"callHandler" method is not injected into InAppBrowser #1973

Description

@7akub
  • I have read the Getting Started section
  • I have already searched for the same problem

Environment

Technology Version
Flutter version 3.13.2
Plugin version 6.0.0
Android version 11, MIUI 12.5.15/12.1.1
iOS version n/a
macOS version n/a
Xcode version n/a
Google Chrome version n/a

Device information: Xiaomi Redmi Note 8 Pro / Xiaomi Mi 9T

Description

Provided code worked fine before I moved from version 5.8.0 to version 6.0.0. After upgrade callHandler is not available from the website opened in InAppBrowser. I've been looking for a solution, but it seems that no one else have been affected by this.

Stoped working only on Android devices, I tested it on iOS 17.1.2 and it works just fine.

Expected behavior:
callHandler method should be injected into InAppBrowser

Current behavior:
callHandler is undefined when creating InAppBrowser

Steps to reproduce

final options = InAppBrowserClassSettings(
  browserSettings: InAppBrowserSettings(
    hideTitleBar: true,
    allowGoBackWithBackButton: false,
    shouldCloseOnBackButtonPressed: true,
    hideToolbarTop: !displayNavigation,
    hideUrlBar: true,
  ),
  webViewSettings: InAppWebViewSettings(
    useShouldOverrideUrlLoading: true,
    javaScriptEnabled: true,
    isInspectable: true,
    clearCache: true,
    clearSessionCache: true,
  ),
);

final InAppBrowser browser = CustomBrowser(
  onCloseCallback: () {
    // Do something
  },
);
  
browser.openUrlRequest(
urlRequest: URLRequest(url: WebUri(url)),
settings: options,
);
class CustomBrowser extends InAppBrowser {
  CustomBrowser({
    this.onCloseCallback,
    int? windowId,
    UnmodifiableListView<UserScript>? initialUserScripts,
  }) : super(
          windowId: windowId,
          initialUserScripts: initialUserScripts,
        );

  final Function()? onCloseCallback;

  @override
  Future onBrowserCreated() async {
    developer.log("Browser Created!");

    if (webViewController != null) {
      developer.log('Adding JS handler');

      webViewController!.addJavaScriptHandler(
        handlerName: JavaScriptHandlerType.closeInAppBrowser,
        callback: (_) {
          if (onCloseCallback != null) {
            onCloseCallback!();
          }

          close();
        },
      );
    }
  }
}

Images

image

image

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