Hello, i have a problem with adding cookies in Cookie Mananger. When i try to set cookie, i get System.Exception: "IBrowserHost instance is null. Browser has likely not finished initializing or is in the process of disposing."
The script works without errors when using Cef.GetGlobalCookieManager(), but I need to set the cookie to this particular browser instance
public partial class Form2 : Form { public Form2(Account account) { InitializeComponent(); var browser = new ChromiumWebBrowser("www.google.com"); RequestContextSettings requestContextSettings = new RequestContextSettings(); requestContextSettings.PersistSessionCookies = false; requestContextSettings.PersistUserPreferences = false; requestContextSettings.CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache\\" + account.steamId); browser.RequestContext = new RequestContext(requestContextSettings); foreach (System.Net.Cookie cookieLine in account.cookie) { if (cookieLine.Name == "steamLoginSecure") { var cookieMananger = browser.GetCookieManager(); Thread.Sleep(5000); cookieMananger.SetCookie("https://steamcommunity.com/", new CefSharp.Cookie { Name = cookieLine.Name, Value = cookieLine.Value, Expires = cookieLine.Expires }); } } browser.Load("https://steamcommunity.com/"); this.Controls.Add(browser); } }
Hello, i have a problem with adding cookies in Cookie Mananger. When i try to set cookie, i get System.Exception: "IBrowserHost instance is null. Browser has likely not finished initializing or is in the process of disposing."
The script works without errors when using Cef.GetGlobalCookieManager(), but I need to set the cookie to this particular browser instance
public partial class Form2 : Form { public Form2(Account account) { InitializeComponent(); var browser = new ChromiumWebBrowser("www.google.com"); RequestContextSettings requestContextSettings = new RequestContextSettings(); requestContextSettings.PersistSessionCookies = false; requestContextSettings.PersistUserPreferences = false; requestContextSettings.CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache\\" + account.steamId); browser.RequestContext = new RequestContext(requestContextSettings); foreach (System.Net.Cookie cookieLine in account.cookie) { if (cookieLine.Name == "steamLoginSecure") { var cookieMananger = browser.GetCookieManager(); Thread.Sleep(5000); cookieMananger.SetCookie("https://steamcommunity.com/", new CefSharp.Cookie { Name = cookieLine.Name, Value = cookieLine.Value, Expires = cookieLine.Expires }); } } browser.Load("https://steamcommunity.com/"); this.Controls.Add(browser); } }