In-App Browser and Chrome Custom Tabs
An in-app browser is a native WebView that floats above your Flutter app instead of living inside the widget tree. You hand it a URL, the platform draws its own chrome (toolbars, close button, menus), and you receive a controller back for the lifetime of that window. This page covers the two facilities the package ships for that job: InAppBrowser, which gives you a full WebView with a per-instance InAppWebViewController, and ChromeSafariBrowser, which is a thin, non-interactive wrapper over the operating system’s own browsing surface — Chrome Custom Tabs on Android and SFSafariViewController on iOS. The distinction matters: reach for InAppBrowser when you need to evaluate JavaScript, intercept navigation, or inject user scripts; reach ChromeSafariBrowser when you just need to show a page with the user’s real browser session and cookies.
Sources: platform_in_app_browser.dart, platform_chrome_safari_browser.dart
The Two Facilities at a Glance
Section titled “The Two Facilities at a Glance”Both classes follow the same federated shape described in Monorepo Layout and the Federated Plugin Model: a public Dart facade in the umbrella package, an abstract platform contract in zikzak_inappwebview_platform_interface, and a native implementation per platform package. The facade holds a platform field, registers itself as that platform object’s eventHandler in its constructor, and re-registers on every open call — a detail that matters if you swap implementations at runtime. ChromeSafariBrowser additionally exposes a set of static members (availability probing, prewarming, package discovery) that route through a separate PlatformChromeSafariBrowser.static() instance, so you can query capability before ever constructing a browser.
| Capability | InAppBrowser |
ChromeSafariBrowser |
|---|---|---|
| Rendering surface | Native WebView in a native window/activity | Chrome Custom Tab / SFSafariViewController |
| Controller access | webViewController (full API) |
None |
| JavaScript bridge | Yes (per-instance channel) | No |
| Menu items | Android, iOS 14.0+ | Android, iOS |
| Post-message channel | No | Android only |
| Trusted Web Activity | No | Android only (isTrustedWebActivity) |
| Prewarming | No | Android, iOS 15+ |
| Officially supported | Android, iOS, macOS, Windows | Android, iOS |
Sources: in_app_browser.dart, chrome_safari_browser.dart, platform_chrome_safari_browser.dart
Choosing Between Them
Section titled “Choosing Between Them”The decision is architectural, not cosmetic. InAppBrowser is a widget-tree escape hatch: the native side inflates a real Activity (Android) or a storyboard navigation controller (iOS), and the Dart side keeps a MethodChannel named after the browser’s generated id so the controller can talk to that specific window. ChromeSafariBrowser deliberately gives up control; the platform interface documentation says so outright and redirects you to InAppWebView if you need to customize or interact with content. Because the Custom Tab runs in the user’s chosen browser process, it shares cookies and credentials with the real browser — which is exactly why it is the right tool for an OAuth flow and the wrong tool for a page you need to instrument.
Sources: platform_chrome_safari_browser.dart, in_app_browser.dart, InAppBrowserManager.java
How an InAppBrowser Opens: The Wire
Section titled “How an InAppBrowser Opens: The Wire”Opening a browser is a two-phase operation. Phase one is entirely Dart-side: _prepareOpenRequest asserts the browser is not already open, flips an _isOpened flag, allocates the per-instance channel wtf.zikzak/zikzak_inappbrowser_$id, and builds the argument map that merges browser settings with WebView settings. Phase two is a single invokeMethod('open', args) on a static channel, which the native manager turns into an Intent carrying the whole map as a serializable Bundle.
flowchart TD A["InAppBrowser.openUrlRequest"] --> B["_prepareOpenRequest<br/>assert not opened, set _isOpened"] B --> C["_init(): MethodChannel<br/>zikzak_inappbrowser_id"] C --> D["invokeMethod('open', args)<br/>static channel"] D --> E["InAppBrowserManager.open()<br/>Bundle extras"] E --> F["startActivity(InAppBrowserActivity)"] F --> G["onCreate: parse settings,<br/>wire WebView + channel delegate"] G --> H["onBrowserCreated -> Dart"] G --> I["onExit -> dispose + callback"]The settings payload is not a bespoke browser-only map. InAppBrowserClassSettings.toMap() concatenates browserSettings.toJson() and webViewSettings.toJson() into one flat map, which is why a single InAppWebViewSettings key such as useShouldOverrideUrlLoading travels the same channel as toolbarTopBackgroundColor. On the native side that same flat map is parsed twice — once by InAppBrowserSettings and once by InAppWebViewSettings — each picking out the keys it owns.
Sources: in_app_browser.dart, in_app_browser.dart, in_app_browser_settings.dart, InAppBrowserManager.java, InAppBrowserActivity.java
Opening a Chrome Custom Tab
Section titled “Opening a Chrome Custom Tab”The Custom Tab path is structurally similar but the routing decision is richer. The native manager reads two flags out of the settings map — isSingleInstance and isTrustedWebActivity — and picks one of four activities accordingly. noHistory then adds FLAG_ACTIVITY_NO_HISTORY to the intent. Availability is decided by CustomTabActivityHelper.isAvailable, which is really a package-resolution question: CustomTabsHelper.getPackageNameToUse enumerates every app that handles VIEW intents and exposes a Custom Tabs connection service, preferring the user’s default handler, then Chrome stable, beta, dev, and the local build in that order. If nothing resolves, open returns a platform error rather than silently falling back.
isSingleInstance |
isTrustedWebActivity |
Activity launched |
|---|---|---|
false |
false |
ChromeCustomTabsActivity |
false |
true |
TrustedWebActivity |
true |
false |
ChromeCustomTabsActivitySingleInstance |
true |
true |
TrustedWebActivitySingleInstance |
All four are declared in the plugin’s AndroidManifest.xml with a transparent theme and exported="false", and the manifest also carries the <queries> entry for android.support.customtabs.action.CustomTabsService that Android 11+ package visibility requires. Omit that entry and getPackageNameToUse returns null on a modern device, which surfaces as “ChromeCustomTabs is not available.”
Sources: ChromeSafariBrowserManager.java, CustomTabActivityHelper.java, CustomTabsHelper.java, AndroidManifest.xml
Chrome Custom Tabs: Sessions, Menus, and the Post-Message Channel
Section titled “Chrome Custom Tabs: Sessions, Menus, and the Post-Message Channel”Once the tab activity is created it binds to the Custom Tabs service in onStart; if binding fails (the browser process is not running) it launches the URL immediately with a null session so the page still opens. A successful bind yields a CustomTabsSession, and that session is the handle for everything interesting: mayLaunchUrl for speculative prefetch, validateRelationship for Digital Asset Links, requestPostMessageChannel and postMessage for two-way messaging, the action button, the secondary toolbar RemoteViews, and engagement-signal callbacks. Because these are session-scoped, the Dart facade forwards them over the per-instance channel wtf.zikzak/flutter_chromesafaribrowser_$id, while open, isAvailable, getMaxToolbarItems, and getPackageName go over the static one.
Menu and action-button clicks do not come back as Dart callbacks over the event channel; they arrive as onItemActionPerform and onSecondaryItemActionPerform messages that the Dart side dispatches by matching the numeric id against its local _menuItems map and _actionButton. Secondary-toolbar clicks are matched by reconstructing the fully qualified resource name (defPackage:defType/name) and comparing it to the name the native side reports. Menu items are Dart-side state only: they are serialized into the open arguments, and the platform contract explicitly notes that mutating them while the browser is open takes effect the next time it opens.
Sources: ChromeCustomTabsActivity.java, ChromeCustomTabsActivity.java, ChromeCustomTabsChannelDelegate.java, chrome_safari_browser.dart, platform_in_app_browser.dart
Keep-Alive, No-History, and Trusted Web Activities
Section titled “Keep-Alive, No-History, and Trusted Web Activities”Three settings change the lifecycle semantics rather than the appearance. keepAliveEnabled attaches an EXTRA_CUSTOM_TABS_KEEP_ALIVE intent pointing at an empty KeepAliveService in your own package; binding to that service raises your app’s process importance so the tab’s process is less likely to be reaped while it is in the background. noHistory sets FLAG_ACTIVITY_NO_HISTORY and registers the browser id with NoHistoryCustomTabsActivityCallbacks, whose activity-lifecycle listener closes and disposes the tab as soon as a FlutterActivity resumes. isTrustedWebActivity swaps in TrustedWebActivity, which builds a TrustedWebActivityIntentBuilder instead of a CustomTabsIntent.Builder and additionally honours additionalTrustedOrigins, displayMode (default or immersive), and screenOrientation; navigation-bar colours are only applied below API 35.
Sources: CustomTabsHelper.java, KeepAliveService.java, ChromeCustomTabsActivity.java, NoHistoryCustomTabsActivityCallbacks.java, TrustedWebActivity.java
The Apple Side
Section titled “The Apple Side”On iOS, ChromeSafariBrowserManager owns a dictionary of SafariViewController instances keyed by the same id and presents the controller on the currently visible view controller. Feature availability is expressed as OS-version gates rather than capability queries: isAvailable is true from iOS 9, clearWebsiteData requires iOS 16 (SFSafariViewController.DataStore), and prewarmConnections / invalidatePrewarmingToken require iOS 15, with tokens held in a dictionary and invalidated on dispose. SafariBrowserSettings parses only the iOS-relevant subset — reader mode, bar collapsing, dismiss-button style, bar tints, presentation and transition styles, plus activityButton (iOS 15) and eventAttribution (iOS 15.2). The Dart facade asserts that the URL is non-null and uses http/https before it ever reaches the channel.
InAppBrowser on iOS is a different mechanism entirely: the manager instantiates the view controller from a storyboard (InAppBrowserNavigationController wrapping InAppBrowserWebViewController), applies hidden to decide whether presentation is animated, configures a popover presentation controller for the popover style, and falls back to UIApplication.shared.open for openWithSystemBrowser after checking canOpenURL. macOS reuses the same class shape but keeps the older dev.zuzu/flutter_inappbrowser static channel name, and Linux — while it registers a LinuxInAppBrowser — registers only a stub PlatformChromeSafariBrowser, so ChromeSafariBrowser is Android/iOS only.
Sources: ChromeSafariBrowserManager.swift, SafariBrowserSettings.swift, chrome_safari_browser.dart, InAppBrowserManager.swift, in_app_browser.dart, inappwebview_platform.dart
Configuration Reference
Section titled “Configuration Reference”InAppBrowserSettings is the browser-chrome half of InAppBrowserClassSettings. The options below are the ones you will reach for first; window-specific keys (windowType, windowStyleMask, windowFrame, windowAlphaValue) exist for the macOS/Windows desktop presentation and are inert on mobile.
| Setting | Default | Effect |
|---|---|---|
hidden |
false |
Create and load without showing; pair with show() |
hideToolbarTop / hideToolbarBottom |
false |
Hide the top/bottom bar |
toolbarTopBackgroundColor |
— | Top bar background |
hideUrlBar |
false |
Hide the URL/search bar |
hideProgressBar |
false |
Hide the loading progress bar |
hideDefaultMenuItems |
false |
Hide back/reload/forward/share |
hideCloseButton |
false |
Hide only the close affordance |
closeButtonCaption / closeButtonColor |
— | Close affordance text/colour |
presentationStyle |
FULL_SCREEN |
Modal presentation style |
transitionStyle |
COVER_VERTICAL |
Modal transition style |
allowGoBackWithBackButton |
true |
Android back navigates history |
closeOnCannotGoBack |
true |
Android back closes at history root |
shouldCloseOnBackButtonPressed |
false |
Android back closes immediately |
For ChromeSafariBrowserSettings the practically important keys are toolbarBackgroundColor, showTitle, enableUrlBarHiding, shareState, dismissButtonStyle, preferredBarTintColor/preferredControlTintColor (iOS), and the Android lifecycle quartet keepAliveEnabled, noHistory, isSingleInstance, isTrustedWebActivity. Note that CustomTabsPostMessageResultType does not use sequential wire values — they are 0, -1, -2, -3 — so the entity carries an explicit wire table rather than relying on Enum.index.
Sources: in_app_browser_settings.dart, chrome_safari_browser_settings.dart, custom_tabs_post_message_result_type.dart
A Practical Caveat: the Close Button Contract
Section titled “A Practical Caveat: the Close Button Contract”hideCloseButton and hideDefaultMenuItems are two independent switches, and the close item is visible exactly when neither is set. This is enforced by a single writer, applyCloseButtonVisibility, which is called both from onCreateOptionsMenu and from setSettings so the initial state and a runtime toggle cannot diverge — a defect that previously shipped on iOS as two inline writers. Two contract tests pin this: one on the Dart side asserting the key survives toJson/fromJson and the InAppBrowserClassSettings merge, and one on the Android side asserting the Java shape (field defaults to false, parse reads the key, toMap reports it, exactly one site resolves R.id.action_close). Treat both as the reason to change visibility in one place only.
Sources: InAppBrowserActivity.java, in_app_browser_close_button_wire_test.dart, in_app_browser_close_button_contract_test.dart
Where to Go Next
Section titled “Where to Go Next”If you have not yet created an inline WebView, start with Quick Start: Your First Inline WebView and then read InAppWebView Widget and InAppWebViewController — the controller you receive from InAppBrowser.webViewController is the same API surface. For the settings objects that travel over these channels, see Domain Controller Facades: Navigation, JavaScript, Cookies, Settings and Zorphy Entity Model Layer and Code Generation. Because an in-app browser owns a native window, its teardown rules are the ones in Disposal Lifecycle and KeepAlive Patterns. Finally, the Android and Apple activity/view-controller plumbing is detailed in Android Native Layer (Java) and Apple Native Layer (Swift and Swift Package Manager).