Skip to content

WebView communication

Send messages to other WebViews.

// Broadcast to all WebViews
SuperSDK.publish('user_login', { userId: '123' });
// Send to specified WebView
SuperSDK.publish('refresh_data', { type: 'order' }, 'a1b2c3d4');

Parameter Description:

ParameterTypeDescription
eventKeystringEvent Identifier
dataobjectMessage Data
targetWebviewIdstringTarget WebView ID, omit or pass ’*’ to broadcast to all

Listen for broadcast messages from other WebViews or clients.

const unsubscribe = SuperSDK.subscribe('user_login', (data) => {
console.log('Message received:', data);
});
// Cancel listener
unsubscribe();

Note: subscribe can receive publish messages from other WebViews, as well as broadcasts sent by the client via sendBroadcast / broadcastToAll.

The host app can send broadcast messages to WebView via SDK API, and the frontend uses subscribe to receive them.

Client-side invocation method:

// Android - Send broadcast to the current WebView
pageView.sendBroadcast("login_changed", "{\"isLogin\":true}");
// Android - Broadcast to all WebViews
SuperSDK.broadcastToAll("config_updated", "{\"key\":\"value\"}");
// iOS - Send broadcast to the current WebView
pageView.sendBroadcast(eventKey: "login_changed", jsonData: "{\"isLogin\":true}")
// iOS - Broadcast to all WebViews
SuperSDK.broadcastToAll(eventKey: "config_updated", jsonData: "{\"key\":\"value\"}")

Front-end reception method:

// Listen to client broadcasts (using subscribe, same as communication with WebView)
SuperSDK.subscribe('login_changed', (data) => {
console.log('Sign-in state changed:', data);
// data = { isLogin: true }
});
SuperSDK.subscribe('config_updated', (data) => {
console.log('Configuration updated:', data);
});

Note: If a broadcast is sent before the JSBridge is ready, the message will be buffered and automatically delivered once the JSBridge is ready.