postWebMessage method
Post a message to main frame. The embedded application can restrict the messages to a certain target origin. See HTML5 spec for how target origin can be used.
A target origin can be set as a wildcard ("*"). However this is not recommended.
NOTE for Android native WebView: This method should only be called if WebViewFeature.isFeatureSupported returns true
for WebViewFeature.POST_WEB_MESSAGE.
NOTE for iOS: it is implemented using JavaScript.
NOTE for MacOS: it is implemented using JavaScript.
Officially Supported Platforms/Implementations:
- Android native WebView (Official API - WebViewCompat.postWebMessage)
- iOS
- MacOS
Implementation
Future<void> postWebMessage(
{required WebMessage message, WebUri? targetOrigin}) =>
platform.postWebMessage(message: message, targetOrigin: targetOrigin);