0
votes

Currently the WebView2 API allows us to execute JS in a hosted page by calling the ExecuteScriptAsync method. The return type is Task<string>. In some of the pages I am trying to integrate the return type from the JS is of Promise<string>. Is there any way I can get the result of the resolved promise, or do I need to ensure that the function in my page is synchronous in order to return a result?

1
A Promise is a javascript thing, I don't think you can return it. - Poul Bak
Thanks @PoulBak, given the similarities to a task in .NET, I was hoping there was some method I am missing that could return it as a .NET task. - rsegner

1 Answers

0
votes

Unfortunately no that's not directly supported. You can open a feature request on our github project. It would be great if we could add support for that.

Currently ExecuteScriptAsync will only give you meaningful return values from the script that is executed synchronously.

As a workaround, you'd need to ExecuteScript to start the asynchronous script execution and then instead of returning the promise in script, use the promise completion to post a message from script to your host app for which you explicitly add a WebMessageReceived event handler.