Documentation
JavaScript Bridge
Communicate with the native app layer
The JavaScript Bridge lets your web application send messages to the native Flutter app shell via window.FlutterWebView.postMessage(). Some features (such as GPS) send data back through a FlutterLocationResponse DOM event; FCM sends FlutterFcmToken.
New: a two-way channel (bridge v2)
Besides these one-off messages, every app has a generic request/response and event channel. Your page calls the app with WebToApp.call(method, params) and gets a promise back, and the app tells your page about things as they happen with WebToApp.on(name, handler): the app coming to the foreground, connectivity changes, notification taps, rewarded ads, purchases. The messages below keep working unchanged. See the Native bridge guide.
Core Syntax
// Check if running in Flutter app
if (window.FlutterWebView) {
window.FlutterWebView.postMessage(JSON.stringify({
type: 'messageType',
// ... additional data
}));
}Message Types
| Type | Direction | Description |
|---|---|---|
userId | Web → App | OneSignal or FCM login/logout (see those guides). With RevenueCat autoIdentify on, it also logs the user in to RevenueCat |
userTags | Web → App | OneSignal tags or FCM topic subscriptions |
getFcmToken | Web → App → Web | Re-dispatch FlutterFcmToken / refresh window.FlutterFcm |
showRewardedAd | Web → App | Show rewarded AdMob ad (see AdMob guide) |
getLocation | Web → App → Web | Device GPS; response on FlutterLocationResponse (see Device Location guide) |
isMobileApp | Web → App → Web | Ask whether the page runs inside the app; answer on WebToAppIsMobileApp (see App Detection guide) |
getPlatform | Web → App → Web | Get ios or android; answer on WebToAppPlatform (see App Detection guide) |
requestAgeSignal | Web → App → Web | Ask iOS / Google Play for the person's age range; response on WebToAppAgeSignal (see Age Verification guide) |
wta.call | Web → App → Web | A bridge v2 method call (app.getInfo, purchases.purchase, …); answered on WebToAppResponse. Use WebToApp.call() instead of sending it yourself (see Native bridge guide) |
The show request for rewarded ads is a message; when the person earns the reward, the app tells your page with the ads.rewardEarned event of the Native bridge.
Platform Detection
You can detect if your site is running inside the WebToApp wrapper by checking for the FlutterWebView object on the window. See App Detection for the helpers, and the Native bridge for app.getInfo, which also reports what the app can do.