addJavaScriptOnEvent method

Future<void> addJavaScriptOnEvent({
  1. required String source,
  2. String event = 'DOMContentLoaded',
})

Injects persistent JavaScript that runs as part of a document lifecycle event.

This is the Android isolated-world / document-event injection API. When the feature is unavailable the call is a no-op.

Officially Supported Platforms/Implementations:

  • Android WebView (Official API - WebViewCompat.addJavaScriptOnEvent):
    • Requires a WebView provider that advertises the document-event script feature.

Parameters - Officially Supported Platforms/Implementations:

  • source: all platforms
  • event: all platforms

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

Implementation

Future<void> addJavaScriptOnEvent({
  required String source,
  String event = 'DOMContentLoaded',
}) => platform.addJavaScriptOnEvent(source: source, event: event);