I'm Using Geckfx22.0
and xulrunner22.0
. Since GeckoWebBrowser in .Net shares cookies with all other instances of GeckoWebBrowsers I would like for a GeckoWebBrowser to have it's own cookie container which doesn't share any cookies that was created previously in other GeckoWebBrowsers or other instances.
For example when I create a GeckoWebBrowser it shouldn't have any cookies. And when I run 2 instances of GeckoWebBrowser they have their own cookie container and don't share or conflict cookies with each other.
How is that possible?
I've tried various possible ways by creating different class and initiating geckofx
but when running different browser at same time it sharing cookies among other browsers. If i remove cookies from one browser , the same happening for other browsers too. I have initiated the proxy
and useragent
at different times and its works but cant apply various useragents for multiple browsers at the same time.
public void Initiate()
{
Gecko.Xpcom.Initialize(AppDomain.CurrentDomain.BaseDirectory + "/xulrunner");
if (this.IsProxySet)
{
Gecko.GeckoPreferences.User["network.proxy.http"] = this.Host;
Gecko.GeckoPreferences.User["network.proxy.http_port"] = this.Port;
Gecko.GeckoPreferences.User["network.proxy.type"] = 1;
}
if (IsUseragentSet)
{
Gecko.GeckoPreferences.User["general.useragent.override"] = this.Useragent;
}
}
And to remove cookies i'm using following code :
nsICookieManager CookieMan;
CookieMan = Xpcom.GetService<nsICookieManager>("@mozilla.org/cookiemanager;1");
CookieMan = Xpcom.QueryInterface<nsICookieManager>(CookieMan);
CookieMan.RemoveAll();
Help will be appreciated !!!
You could possibly try implementing your own cookie manager that supports this:
see unittest Register_AfterDefaultFactoryHasBeenUnregistered_NewCookieServiceIsUsedInsteadOfDefaultOne for an example of how to do this.
This code is currently untested and may contain typeos
This code requires a geckofx version newer than v22.0-0.6
[Guid("c375fa80-150f-11d6-a618-0010a401eb10")]
[ContractID(TestCookieServiceFactory.ContractID)]
public class TestCookieServiceFactory
: GenericOneClassNsFactory<TestCookieServiceFactory, TestCookieService>
{
public const string ContractID = "@mozilla.org/cookieService;1";
}
public class TestCookieService : nsICookieService
{
// Implement nsICookieService...
}
public void Main()
{
Xpcom.Initialize("My Xulrunner/Fireofox location");
var existingFactoryDetails = TestCookieServiceFactory.Unregister();
TestCookieServiceFactory.Register();
var browser = new GeckofxWebBrowser();
// Add browser to form etc...
browser.Navigate("http://SomeWebPageThatUsesCookies")
// Cookie requests should now be sent to TestCookieService, process them as your want.
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With