Search code examples
javascript.netwinformscefsharpchromium-embedded

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


Solution

  • This has been solved now, in version 88 of cefsharp: https://github.com/cefsharp/CefSharp/wiki/Advanced-Async-JavaScript-Binding-(JSB)/07c45fa962174d0476c4f2206f707365e9b11edd#javascript-callback-with-promise