postWebMessage method

  1. @SupportedPlatforms.new(platforms: [AndroidPlatform(apiName: 'WebView.postWebMessage', apiUrl: 'https://developer.android.com/reference/androidx/webkit/WebViewCompat#postWebMessage(android.webkit.WebView,%20androidx.webkit.WebMessageCompat,%20android.net.Uri)', note: 'This method should only be called if [WebViewFeature.isFeatureSupported] returns `true` for [WebViewFeature.POST_WEB_MESSAGE].'), IOSPlatform(note: 'This method is implemented using JavaScript.'), MacOSPlatform(note: 'This method is implemented using JavaScript.'), LinuxPlatform(note: 'Implemented via JavaScript MessageChannel API.'), WindowsPlatform(note: 'Implemented via JavaScript MessageChannel API.')])
Future<void> postWebMessage({
  1. required WebMessage message,
  2. WebUri? targetOrigin,
})

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.

Officially Supported Platforms/Implementations:

Parameters - Officially Supported Platforms/Implementations:

  • message: all platforms
  • targetOrigin: all platforms

Use the PlatformInAppWebViewController.isMethodSupported method to check if this method is supported at runtime.

Implementation

@SupportedPlatforms(
  platforms: [
    AndroidPlatform(
      apiName: 'WebView.postWebMessage',
      apiUrl:
          'https://developer.android.com/reference/androidx/webkit/WebViewCompat#postWebMessage(android.webkit.WebView,%20androidx.webkit.WebMessageCompat,%20android.net.Uri)',
      note:
          'This method should only be called if [WebViewFeature.isFeatureSupported] returns `true` for [WebViewFeature.POST_WEB_MESSAGE].',
    ),
    IOSPlatform(note: 'This method is implemented using JavaScript.'),
    MacOSPlatform(note: 'This method is implemented using JavaScript.'),
    LinuxPlatform(note: 'Implemented via JavaScript MessageChannel API.'),
    WindowsPlatform(note: 'Implemented via JavaScript MessageChannel API.'),
  ],
)
Future<void> postWebMessage({
  required WebMessage message,
  WebUri? targetOrigin,
}) {
  throw UnimplementedError(
    '${PlatformInAppWebViewControllerMethod.postWebMessage.name} is not implemented on the current platform',
  );
}