最近发现升级 CefSharp 到最新版本(86.0.241)后无法使用JS直接调用C#类了
以前使用的83.4.20版本,直接使用Register注册,就可以在JS中使用注册名 "callbackObj" 直接调用到注册的C#类
具体代码:
private readonly ChromiumWebBrowser _browser;
public MainForm()
{
InitializeComponent();
_browser = new ChromiumWebBrowser(URL)
{
Dock = DockStyle.Fill,
};
this.Controls.Add(browser);
CallbackObjectForJs callbackObjectForJs = new CallbackObjectForJs();
CefSharpSettings.LegacyJavascriptBindingEnabled = true;
CefSharpSettings.WcfEnabled = true;
//注册
_browser.JavascriptObjectRepository.Register("callbackObj", callbackObjectForJs, isAsync: false, options: BindingOptions.DefaultBinder);
// 按F12显示调试工具
_browser.KeyboardHandler = new CEFKeyBoardHan