CefSharp F12打开DevTools查看console

winform嵌入chrome浏览器,修改项目属性 生成 平台为x86

1.nuget安装cefsharp

2.实例化浏览器

private void Form1_Load(object sender, EventArgs e)
{

CefSettings settings = new CefSettings();
settings.CefCommandLineArgs.Add("--disable-web-security","1");//关闭同源策略,允许跨域
settings.CefCommandLineArgs.Add("ppapi-flash-version", "18.0.0.209");//PepperFlash\manifest.json中的version
settings.CefCommandLineArgs.Add("ppapi-flash-path", "PepperFlash\\pepflashplayer.dll");
settings.CefCommandLineArgs.Add("--enable-system-flash", "1");//使用系统flash
Cef.Initialize(settings);

/*以上设置未测试是否可行*/

ChromiumWebBrowser b = new ChromiumWebBrowser("http://localhost:57531/views/Map/scene.html");
this.Controls.Add(b);
b.Dock = DockStyle.Fill;
b.KeyboardHandler = new CEFKeyBoardHander();
}

3.响应F12打开控制台console

public class CEFKeyBoardHander : IKeyboardHandler
{//https://bbs.csdn.net/topics/392375553
public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey)
{
if (type == KeyType.KeyUp && Enum.IsDefined(typeof(Keys), windowsKeyCode))
{
var key = (Keys)windowsKeyCode;
switch (key)
{
case Keys.F12:
browser.ShowDevTools();
break;

case Keys.F5:

if (modifiers == CefEventFlags.ControlDown)
{
//MessageBox.Show("ctrl+f5");
browser.Reload(true); //强制忽略缓存

}
else
{
//MessageBox.Show("f5");
browser.Reload();
}
break;


}
}
return false;
}

public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut)
{
return false;
}
}

From: https://www.cnblogs.com/xuejianxiyang/p/9981398.html

上一篇:Etcd入门教程


下一篇:Python学习笔记8—语句