CefSharp 基础知识汇总
1.1 cefsharp设置默认语言
cefsharp是不错的浏览器内核封装版本之一,默认语言是en-US。 CefSettings 的 Loacal 属性就是对CefSharp运行语言环境进行设置
var setting = new CefSharp.CefSettings();
// 设置语言
setting.Locale = “zh-CN”;
CefSharp.Cef.Initialize(setting, true, false); 以上这段代码一定要在new ChromiumWebBrowser之前调用
1.2 cefSharp 服务器运行要求
.net framework 环境和 vc++ 2013 runtime (x86/x64),具体使用根据CefSharp版本的不同选择相应的.net framework 和VC++运行时
Branch/分支 | CEF Version/Cef 版本 | VC++ Version/VC++版本 | .Net Version/.Net版本 | Status/状态 |
---|---|---|---|---|
master | 2883 | 2013 | 4.5.2 | Development/开发中 |
cefsharp/57 | 2987 | 2013 | 4.5.2 | Pre-Release/预发布 |
cefsharp/55 | 2883 | 2013 | 4.5.2 | Release/已发布 |
cefsharp/53 | 2785 | 2013 | 4.5.2 | Unsupported 不再维护 |
cefsharp/51 | 2704 | 2013 | 4.5.2 | Unsupported 不再维护 |
cefsharp/49 | 2623 | 2013 | 4.0 | Unsupported 不再维护 |
cefsharp/47 | 2526 | 2013 | 4.0 | Unsupported 不再维护 |
cefsharp/45 | 2454 | 2013 | 4.0 | Unsupported 不再维护 |
cefsharp/43 | 2357 | 2012 | 4.0 | Unsupported 不再维护 |
cefsharp/41 | 2272 | 2012 | 4.0 | Unsupported 不再维护 |
cefsharp/39 | 2171 | 2012 | 4.0 | Unsupported 不再维护 |
cefsharp/37 | 2062 | 2013 | 4.0 | Unsupported 不再维护 |
1.3 cefsharp设置网页接受语言AcceptLanguage
什么是 cefsharp设置网页接受语言AcceptLanguage
1.设置浏览器的请求控制器
webView.RequestHandler = new RequestHandler();
2.新建RequestHandler类继承IRequestHandler接口,实现方法OnBeforeResourceLoad,新版本如果又变更但是整体思路不变,内部处理是一致的。
public bool OnBeforeResourceLoad(IWebBrowser browser, IRequestResponse requestResponse) { IDictionary<string, string> headers = requestResponse.Request.GetHeaders(); headers.Add("Accept-Language", "zh,zh-cn,zh-tw"); requestResponse.Request.SetHeaders(headers); return false; }
1.4 cef设置userAgent
var setting = new CefSharp.CefSettings(); setting.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"; CefSharp.Cef.Initialize(setting, true, false);