runJavascriptReturningResult method

  1. @override
Future<String> runJavascriptReturningResult(
  1. String javascript
)

See WebViewController.runJavascriptReturningResult or WebViewPlatformController.runJavascriptReturningResult.

On Linux, returns the evaluation result as a JSON formatted string.

Implementation

@override
Future<String> runJavascriptReturningResult(String javascript) async {
  final int? webviewId = instanceManager.getInstanceId(this);
  if (webviewId == null) {
    throw 'Failed to get the webview instance';
  }

  _JavascriptResult jsResult =
      await _runJavascriptInternal(webviewId, javascript);
  if (!jsResult.wasExecuted) {
    throw "javascript was not executed for some reason";
  }
  if (jsResult.isException) {
    throw jsResult.result; // js error string
  }
  if (jsResult.isUndefined) {
    return "undefined";
  }
  return jsResult.result;
}