RegisterJsObject CefSharp not work

salvo italy picture salvo italy · Feb 12, 2015 · Viewed 10.9k times · Source

I have that problem whith CefSharp and js communication. This is my structure. In my MainWindow.xaml.cs I have:

chromium = new CefSharp.Wpf.ChromiumWebBrowser();
chromium.RegisterJsObject("jsInterface", new jsMapInterface());

where jsMapInterface is a public class with its methods.

In my html/js folder, I call a C# method with:

window.jsInterface.myTest();
//jsInterface.myTest();  //I have tested twice

where myTest() is a method inside jsMapInterface class but nothing happens. Where is my mistake?

Thanks in advise.

Answer

jornh picture jornh · Feb 12, 2015

Try UpperCasing on the C# side e.g MyTest() as mentioned under Please note in https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#3-how-do-you-expose-a-net-class-to-javascript

CefSharp does perform name mangling. The reason is it tries to encourage following JS conventions on the JS side and C# conventions on that side.

Finally work from the example code at https://github.com/cefsharp/CefSharp/search?utf8=%E2%9C%93&q=BoundObject