Hi there, I've encountered a problem when performing JS command (loading a content in WebView).
Here is an exception:
-- Message: --
Object 'System.Threading.Tasks.Task`1[System.Object]' of type 'System.Threading.Tasks.Task`1[System.Object]' can not be passed to JavaScript code.
-- Source: --
EO.WebBrowser
-- Stack trace: --
at EO.WebBrowser.JSObject.a(Object A_0, l1 A_1)
at EO.WebBrowser.WebView.v(co A_0, ap9 A_1)
at EO.WebBrowser.WebView.a(co A_0, ap9 A_1)
at EO.WebBrowser.WebView.b(co A_0, ap9 A_1)
and my code:
Code: C#
public async Task<T> CallTopScreenWithResult<T>(string header, object obj)
{
if (WebControlTopScreen?.WebView == null || _lastWebState != WebAppState.Online)
throw new InvalidOperationException("Can not call Top screen at this moment");
var result = await WebControlTopScreen.WebView.PerformJsCommandWithResultAsync<T>("listenTopScreen", new object[] { header, obj });
if (result is JSUndefined)
result = default(T);
return result;
}
public static async Task<T> PerformJsCommandWithResultAsync<T>(this WebView webView, string methodName, object[] methodArguments)
{
try
{
if (webView.CreatedByThisThread() == false && webView.CanEvalScript)
return (T)webView.EvalScript(GetJavascriptFunctionString(methodName, methodArguments), true);
var taskCompletionSource = new TaskCompletionSource<object>();
var call = webView.QueueScriptCall(GetJavascriptFunctionString(methodName, methodArguments));
call.OnDone(() => taskCompletionSource.SetResult(call.Result));
return (T)await taskCompletionSource.Task;
}
catch (Exception ex)
{
LogJavascriptExceptionMessage(ex, methodName, methodArguments);
throw;
}
}
This output is from my WPF app, EO lib. version 19.2.91.
The most interesting is that I use this same method in WinForms, same EO version and it works very well.
I've also tried the latest version but it hasn't helped unfortunately.
Let me know if more info needed, thanks!