runJavaScriptReturningResult method

  1. @override
Future<Object> runJavaScriptReturningResult(
  1. String javaScript
)

Runs the given JavaScript in the context of the current page, and returns the result.

The Future completes with an error if a JavaScript error occurred, or if the type the given expression evaluates to is unsupported. Unsupported values include certain non-primitive types on iOS, as well as undefined or null on iOS 14+.

Implementation

@override
Future<Object> runJavaScriptReturningResult(String javaScript) async {
  final Object? result = await _webView.evaluateJavaScript(javaScript);
  if (result == null) {
    throw ArgumentError(
      'Result of JavaScript execution returned a `null` value. '
      'Use `runJavascript` when expecting a null return value.',
    );
  }
  return result;
}