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.

Core Syntax

// Check if running in Flutter app
if (window.FlutterWebView) {
    window.FlutterWebView.postMessage(JSON.stringify({
        type: 'messageType',
        // ... additional data
    }));
}

Message Types

TypeDirectionDescription
userIdWeb → AppOneSignal login/logout (see OneSignal guide)
userTagsWeb → AppOneSignal user tags for segmentation
showRewardedAdWeb → AppShow rewarded AdMob ad (see AdMob guide)
getLocationWeb → App → WebDevice GPS; response on FlutterLocationResponse (see Device Location guide)

Rewarded ad completion is not sent back to the website yet — only the show request is supported from JavaScript.

Platform Detection

You can detect if your site is running inside the WebToApp wrapper by checking for the FlutterWebView object on the window.