I'm using DotNetBrowser as a sort of headless Javascript engine within a .Net app. It seems DotNetBrowser has no support for Promises, or I am not using invoking them properly.
In JS:
window.fooAsyncMethod = () => {
return new Promise((resolve, reject) => {
resolve('async value to resolve');
});
}
In C#:
var result = await browser.MainFrame.ExecuteJavascript("await window.fooAsyncMethod()")
In this case, the result is always null. I've tried async/await as well, and always receive null:
window.fooAsyncMethod = async () => {
return await someOtherAsyncMethod()
}
Does DotNetBrowser support running asynchronous javascript or not? And if so, how can I achieve awaiting the result of an asynchronous operation and resolving that value within C#?
Looking over the JS-.NET bridge examples it appears that it does support promises however they are a bit more involved to use.
If you implement a type of promise object on your C# side as such:
You will then be able to call the promise like this:
Please note that all the above code was taken directly from their Promises Example.