0

I am using cefSharp in my winForm application. I want to pass a long json from my winform to the html page displayed by the cefSharp. I tried to write the following:

Private WithEvents m_chromeBrowser As ChromiumWebBrowser
...
CefSharp.Cef.Initialize()
page = New Uri("www...")
m_chromeBrowser = New ChromiumWebBrowser(page.ToString)
Panel.Controls.Add(m_chromeBrowser)
...
Dim json as String = "[{code:1,name:a,val:0},{...}....]"
m_chromeBrowser.ExecuteScriptAsync("functionName('" & json & "');")

But I keep getting the following error:

Request-URI Too Long

Do you have any idea how to pass long json from winform to browser.

Thanks

varda
  • 11
  • 4

1 Answers1

0

Well, you would be better off exposing a .Net class to JavaScript by registering an AsyncJSObject, execute the class method from JavaScript and parse the return result.

Something like this:

public class CallbackObjectForJs {
    public string getJson() {
        return myJsonString;
    }
}

... then register the class:

_webBrowser.RegisterAsyncJsObject(
    "Browser", 
    new CallbackObjectForJs(), 
    BindingOptions.DefaultBinder);

... and finally call the method from Javascript and use a promise to get the result:

Browser.getJson().then((result) => {
    var myJsonString = JSON.parse(result);
    console.log(myJsonString);
});

You can read more about it here: https://github.com/cefsharp/CefSharp/wiki/General-Usage#3-how-do-you-expose-a-net-class-to-javascript

Hope it helps!

Reinaldo
  • 4,556
  • 3
  • 24
  • 24