runJavaScript method
Runs the given JavaScript in the context of the current page.
The Future completes with an error if a JavaScript error occurred.
Implementation
@override
Future<void> runJavaScript(String javaScript) async {
try {
await _webView.evaluateJavaScript(javaScript);
} on PlatformException catch (exception) {
// WebKit will throw an error when the type of the evaluated value is
// unsupported. This also goes for `null` and `undefined` on iOS 14+. For
// example, when running a void function. For ease of use, this specific
// error is ignored when no return value is expected.
final Object? details = exception.details;
if (details is! NSError ||
details.code != WKErrorCode.javaScriptResultTypeIsUnsupported) {
rethrow;
}
}
}