createWebMessageChannel method

  1. @SupportedPlatforms.new(platforms: [AndroidPlatform(apiName: 'WebViewCompat.createWebMessageChannel', apiUrl: 'https://developer.android.com/reference/androidx/webkit/WebViewCompat#createWebMessageChannel(android.webkit.WebView)', note: 'This method should only be called if [WebViewFeature.isFeatureSupported] returns `true` for [WebViewFeature.CREATE_WEB_MESSAGE_CHANNEL].'), 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<PlatformWebMessageChannel?> createWebMessageChannel()

Creates a message channel to communicate with JavaScript and returns the message channel with ports that represent the endpoints of this message channel. The HTML5 message channel functionality is described here.

The returned message channels are entangled and already in started state.

This method should be called when the page is loaded, for example, when the PlatformWebViewCreationParams.onLoadStop is fired, otherwise the PlatformWebMessageChannel won't work.

Officially Supported Platforms/Implementations:

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

Implementation

@SupportedPlatforms(
  platforms: [
    AndroidPlatform(
      apiName: 'WebViewCompat.createWebMessageChannel',
      apiUrl:
          'https://developer.android.com/reference/androidx/webkit/WebViewCompat#createWebMessageChannel(android.webkit.WebView)',
      note:
          'This method should only be called if [WebViewFeature.isFeatureSupported] returns `true` for [WebViewFeature.CREATE_WEB_MESSAGE_CHANNEL].',
    ),
    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<PlatformWebMessageChannel?> createWebMessageChannel() {
  throw UnimplementedError(
    '${PlatformInAppWebViewControllerMethod.createWebMessageChannel.name} is not implemented on the current platform',
  );
}