CEF浏览器配置
CefSettings cefSettings = new CefSettings(); cefSettings.Locale = "zh-CN"; cefSettings.CachePath = str + "cache"; cefSettings.AcceptLanguageList = "zh-CN"; //cefSettings.CefCommandLineArgs.Add("disable-application-cache", "1"); //cefSettings.CefCommandLineArgs.Add("disable-session-storage", "1"); Cef.Initialize(cefSettings); CefSharpSettings.LegacyJavascriptBindingEnabled = true;
RegisterJsObject
class JsEvent { public string MessageText = string.Empty; public void showTest() { MessageBox.Show("this in C#.\n\r" + MessageText); } } void intjs(ExtChromiumBrowser chromiumWeb) { var JsEvent = new JsEvent(); chromiumWeb.RegisterJsObject("jsObj", JsEvent, BindingOptions.DefaultBinder); }function myfunction(){ jsObj.MessageText = "hello"; jsObj.showTest();}
COOKIE
class CookieClear : ICookieVisitor { public bool Visit(Cookie cookie, int count, int total, ref bool deleteCookie) { deleteCookie = true; return true; } public void Dispose() { } }CookieClear cookieClear; cookieClear = new CookieClear(); if (Cef.GetGlobalCookieManager().VisitAllCookies(cookieClear)) { }
COOK
public class CookieVisitor : ICookieVisitor { public CookieVisitor(string Domainurl) { Domain = Domainurl; } public event ActionSendCookie; public string cookies = ""; public string Domain; public bool Visit(CefSharp.Cookie cookie, int count, int total, ref bool deleteCookie) { deleteCookie = false; if (SendCookie != null) { SendCookie(cookie); cookies += cookie.Value; } return true; } public void Dispose() { } } static string cookies; /// 回调事件 private static void visitor_SendCookie(CefSharp.Cookie obj) { cookies += obj.Domain.TrimStart('.') + "^" + obj.Name + "^" + obj.Value + "$"; }CookieVisitor visitor = new CookieVisitor(); visitor.SendCookie += visitor_SendCookie; if (Cef.GetGlobalCookieManager().VisitAllCookies(visitor)) { }