Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegisterJsObject CefSharp not work

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.

like image 739
salvo italy Avatar asked Dec 24 '22 22:12

salvo italy


1 Answers

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

like image 198
jornh Avatar answered Dec 27 '22 21:12

jornh