I have javascript function which uses CefSharp.ChroniumBrowser (WinForms). I registered "jsObject" as script object for browser: Browser.RegisterJsObject(new JsObject()). C# code:
public class JsObject
{
//...
public async void IsServerConnected(IJavascriptCallback callback)
{
var result = await Server.GetConnectionResult();
callback.ExecuteAsync(result);
}
}
The following js code calls C# method which asynchronously checks whether server is connected and executes callback with result.
function isServerConnected(callback) {
window.jsObject.isServerConnected(function (connected) {
callback(connected);
});
}
and to get the result I should write:
isServerConnected(function(result) {
if (result) {
// server is connected. do something
} else {
// show error
}
});
I would like to get the result in such a way:
var result = isServerConnected();
if (result){
...
} else {
...
}
Is it possible to make this work? Maybe promises should help but how I can get the result without using callbacks in the ending call: var result = isServerConnected(); ?