将 CefSharp 版本从 v.57 更新到版本 75.1.143 时注册 CefSharp 的 JS 方法更改
Register JS methods change for CefSharp while updating cefsharp version from v. 57 to version 75.1.143
我们在我们的应用程序中使用的是 cefsharp 57.0 版,它运行良好。但现在由于一些限制,我们需要将 cefsharp 版本更新到 75.1.143,突然我们的工作代码崩溃了。一项更改是将 LegacyJavascriptBindingEnabled 更改为 true,其次,此行中断:
browser.RegisterJsObject("objectForCallingServerSideMethods", this);
出现错误 System.ArgumentException:不支持注册 .Net Framework 内置类型,如果您需要访问 window/Form/Control,请创建您自己的对象并代理调用。参数名称:值。
一切正常。我不知道该如何处理。示例代码在这里,它在更新之前是有效的。
Cef.Initialize(new CefSettings() { IgnoreCertificateErrors = true, PersistSessionCookies = true, CachePath = LocalFolderPath + "/cache" });
CefSharpSettings.ShutdownOnExit = true;
CefSharpSettings.LegacyJavascriptBindingEnabled = true; // added now for version 75.1.143
browser = new ChromiumWebBrowser("url goes here");
browser.DownloadHandler = new DownloadHandler();
browser.Width = 0;
browser.Height = 0;
browser.MenuHandler = new CustomContextHandler();
this.Controls.Add(browser);
browser.LoadingStateChanged += Browser_LoadingStateChanged;
browser.RegisterJsObject("objectForCallingServerSideMethods", this); // this line is throwing exception now. screenshot is attached.
我已经整理出它的解决方案了。我将 winform 对象作为 'this' 传递,在版本 75.1.143 中他们更改了实现,现在我们不能使用 Window/Form/Control。我创建了另一个名为 "BoundObject" 的 class 并传递了它的对象,它按预期工作。
public class BoundObject
{
// some implementation
// all methods from JS will be catched in this class. Before this (in version 57) we were receiving these methods from JS on windows form.
}
browser.RegisterJsObject("objectForCallingServerSideMethods", new BoundObject());
我们在我们的应用程序中使用的是 cefsharp 57.0 版,它运行良好。但现在由于一些限制,我们需要将 cefsharp 版本更新到 75.1.143,突然我们的工作代码崩溃了。一项更改是将 LegacyJavascriptBindingEnabled 更改为 true,其次,此行中断:
browser.RegisterJsObject("objectForCallingServerSideMethods", this);
出现错误 System.ArgumentException:不支持注册 .Net Framework 内置类型,如果您需要访问 window/Form/Control,请创建您自己的对象并代理调用。参数名称:值。 一切正常。我不知道该如何处理。示例代码在这里,它在更新之前是有效的。
Cef.Initialize(new CefSettings() { IgnoreCertificateErrors = true, PersistSessionCookies = true, CachePath = LocalFolderPath + "/cache" });
CefSharpSettings.ShutdownOnExit = true;
CefSharpSettings.LegacyJavascriptBindingEnabled = true; // added now for version 75.1.143
browser = new ChromiumWebBrowser("url goes here");
browser.DownloadHandler = new DownloadHandler();
browser.Width = 0;
browser.Height = 0;
browser.MenuHandler = new CustomContextHandler();
this.Controls.Add(browser);
browser.LoadingStateChanged += Browser_LoadingStateChanged;
browser.RegisterJsObject("objectForCallingServerSideMethods", this); // this line is throwing exception now. screenshot is attached.
我已经整理出它的解决方案了。我将 winform 对象作为 'this' 传递,在版本 75.1.143 中他们更改了实现,现在我们不能使用 Window/Form/Control。我创建了另一个名为 "BoundObject" 的 class 并传递了它的对象,它按预期工作。
public class BoundObject
{
// some implementation
// all methods from JS will be catched in this class. Before this (in version 57) we were receiving these methods from JS on windows form.
}
browser.RegisterJsObject("objectForCallingServerSideMethods", new BoundObject());