evaluateJavascript method
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 and on Windows platforms.
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:
- Android native WebView (Official API - WebView.evaluateJavascript)
- iOS (Official API - WKWebView.evaluateJavascript)
- MacOS (Official API - WKWebView.evaluateJavascript)
- Web (Official API - Window.eval)
- Windows
Implementation
Future<dynamic> evaluateJavascript(
{required String source, ContentWorld? contentWorld}) {
throw UnimplementedError(
'evaluateJavascript is not implemented on the current platform');
}