Hi,
You won't be able to use async/await effectively with EvalScript because async function returns a Promise that is to be fulfilled or rejected later that can occur after EvalScript returns.
An easier way to understand await is to think an await split a single function into two functions. So the following function:
Code: JavaScript
async function f(imageUrl)
{
let response = await fetch(imageUrl);
return 1;
}
In fact can be written this way:
Code: JavaScript
function OnDone()
{
return 1;
}
function f(imageUrl)
{
var promise = fetch(imageUrl);
promise.OnDone = OnDone;
return promise;
}
Note that the Promise object does not actually have an OnDone event. So the above code is only for demonstrating purpose.
Obviously calling f with EvalScript will return the promise object that you would not be able to do much about it. The key here is await does NOT wait. It simply yield the control and promise to resume at a later time.
When you enter code in Chrome's Developer Tools console, it would wrap your code into an anonymous function and then call that function. This is why when you type await directly in the script console it will take it but if you call WebView.EvalScript it won't take it because WebView.EvalScript does not automatically use an anonymous function around your script code.
Hope this helps.
Thanks!