Borja Fernández
Borja Fernández

Reputation: 159

CefSharp Javascript Callback never return resolved promise

First of all, excuse my English, it's very bad. I am using CefSharp in WinForms app for comunication between navigator and .NET code.

I'm trying to resolve a promise in an asynchronous callback function with CefSharp, but in the response returned to .Net I never get the response of the resolved promise, but rather an object that seems to represent the consumers of said promise (finally, catch, then).

Is there any way to solve this?

I leave an example that I hope can help you in understanding the problem.

//C# code

public void TestCallback(IJavascriptCallback javascriptCallback)
{
    const int taskDelay = 1500;
    Task.Run(async () =>
    {
        await Task.Delay(taskDelay);
        using (javascriptCallback)
        {
            var result = await javascriptCallback.ExecuteAsync();
            //result is a JavaScriptResponse, but property "Result" is not "user" object, is a dictionary object with 'then', 'catch', 'finally' keys. 
        }
    });
}

//JS code

function async MyCallback()
{
  // read our JSON
  let response = await fetch('/article/promise-chaining/user.json');
  let user = await response.json();
  return user;
}
boundAsync.testCallback(MyCallback);

Thank you very much.

Regards

Borja

Upvotes: 2

Views: 1169

Answers (1)

Related Questions