onCreateWindow method

  1. @override
Future<bool?>? onCreateWindow(
  1. CreateWindowAction createWindowAction
)
override

Event fired when the PlatformInAppBrowser webview requests the host application to create a new window, for example when trying to open a link with target="_blank" or when window.open() is called by JavaScript side. If the host application chooses to honor this request, it should return true from this method, create a new WebView to host the window. If the host application chooses not to honor the request, it should return false from this method. The default implementation of this method does nothing and hence returns false.

createWindowAction represents the request.

NOTE: to allow JavaScript to open windows, you need to set InAppWebViewSettings.javaScriptCanOpenWindowsAutomatically setting to true.

NOTE: on Android you need to set InAppWebViewSettings.supportMultipleWindows setting to true.

NOTE: on iOS and MacOS, setting these initial settings: InAppWebViewSettings.supportZoom, InAppWebViewSettings.useOnLoadResource, InAppWebViewSettings.useShouldInterceptAjaxRequest, InAppWebViewSettings.useShouldInterceptFetchRequest, InAppWebViewSettings.applicationNameForUserAgent, InAppWebViewSettings.javaScriptCanOpenWindowsAutomatically, InAppWebViewSettings.javaScriptEnabled, InAppWebViewSettings.minimumFontSize, InAppWebViewSettings.preferredContentMode, InAppWebViewSettings.incognito, InAppWebViewSettings.cacheEnabled, InAppWebViewSettings.mediaPlaybackRequiresUserGesture, InAppWebViewSettings.resourceCustomSchemes, InAppWebViewSettings.sharedCookiesEnabled, InAppWebViewSettings.enableViewportScale, InAppWebViewSettings.allowsAirPlayForMediaPlayback, InAppWebViewSettings.allowsPictureInPictureMediaPlayback, InAppWebViewSettings.isFraudulentWebsiteWarningEnabled, InAppWebViewSettings.allowsInlineMediaPlayback, InAppWebViewSettings.suppressesIncrementalRendering, InAppWebViewSettings.selectionGranularity, InAppWebViewSettings.ignoresViewportScaleLimits, InAppWebViewSettings.limitsNavigationsToAppBoundDomains, InAppWebViewSettings.upgradeKnownHostsToHTTPS, will have no effect due to a WKWebView limitation when creating a new window WebView: it's impossible to return a new WKWebView with a different WKWebViewConfiguration instance (see https://developer.apple.com/documentation/webkit/wkuidelegate/1536907-webview). So, these options will be inherited from the caller WebView. Also, note that calling PlatformInAppWebViewController.setSettings method using the controller of the new created WebView, it will update also the WebView options of the caller WebView.

Officially Supported Platforms/Implementations:

Implementation

@override
Future<bool?>? onCreateWindow(CreateWindowAction createWindowAction) {
  return null;
}