evaluateJavascript method

Future evaluateJavascript(
  1. {required String source,
  2. ContentWorld? contentWorld}
)

Evaluates JavaScript source code into the WebView and returns the result of the evaluation.

contentWorld, on iOS, it represents the namespace in which to evaluate the JavaScript source code. Instead, on Android, it will run the source code into an iframe, using eval(source); to get and return the result. This parameter doesn’t apply to changes you make to the underlying web content, such as the document’s DOM structure. Those changes remain visible to all scripts, regardless of which content world you specify. For more information about content worlds, see ContentWorld. Available on iOS 14.0+ and MacOS 11.0+. NOTE: not used on Web.

NOTE: This method shouldn't be called in the PlatformWebViewCreationParams.onWebViewCreated or PlatformWebViewCreationParams.onLoadStart events, because, in these events, the WebView is not ready to handle it yet. Instead, you should call this method, for example, inside the PlatformWebViewCreationParams.onLoadStop event or in any other events where you know the page is ready "enough".

NOTE for Web: this method will have effect only if the iframe has the same origin.

Officially Supported Platforms/Implementations:

Implementation

Future<dynamic> evaluateJavascript(
        {required String source, ContentWorld? contentWorld}) =>
    platform.evaluateJavascript(source: source, contentWorld: contentWorld);