1 安装 CefSharp.WinForms.NETCore
2 在窗口内执行代码
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
chromeBrowser = new ChromiumWebBrowser("http://localhost:5000/");
// 注册Js 对象
chromeBrowser.JavascriptObjectRepository.Register("boundCef", new BoundObject(this, chromeBrowser),BindingOptions.DefaultBinder);
this.Controls.Add(chromeBrowser);
public class BoundObject {
private readonly Sample _sample;
private readonly ChromiumWebBrowser chromeBrowser;
public BoundObject(Sample sample, ChromiumWebBrowser chromiumWebBrowser)
{
chromeBrowser = chromiumWebBrowser;
_sample = sample;
}
public void ShowMessage(){
MessageBox.show("测试调用");
}
}