Each Browser instance must be created using BrowserFactory. BrowserFactory initializes the context that is needed for a browsing session and provides the path to the directory where Chromium stores cookies, cache data files, etc.


The following code creates a new Browser instance initialized with default context:

Browser browser = BrowserFactory.Create();

The code above equals to:

Browser browser = BrowserFactory.Create(BrowserContext.DefaultContext);

The BrowserContext.DefaultContext property is a default BrowserContext that is configured to store Chromium data files such as cookies, cache, etc. in user's temp directory. You can get absolute path to the directory where the data files are stored using the BrowserPreferences.GetDefaultDataDir() method.


Two Browser instances with same BrowserContext will use the same user data directory. As result, they will share cookies and cache files. For example:

BrowserContextParams params= new BrowserContextParams("C:\\my-data1");
BrowserContext context = new BrowserContext(params);

Browser browser1 = BrowserFactory.Create(context);
Browser browser2 = BrowserFactory.Create(context);

To create independent Browser instances that don't share cookies and cache data, you must initialize each Browser instance with a different BrowserContext configured to use different data directory. For example:

BrowserContextParams params1= new BrowserContextParams("C:\\my-data1");
BrowserContext context1 = new BrowserContext(params);
Browser browser1 = BrowserFactory.Create(context1);

BrowserContextParams params2= new BrowserContextParams("C:\\my-data2");
BrowserContext context2 = new BrowserContext(params2);
Browser browser2 = BrowserFactory.Create(context2);

To get BrowserContext of the Browser instance you can use the browser.Context property.


Important: please make sure that you don't use several BrowserContext instances configured to use same data directory.  In this case Chromium engine will read/write same data directory from different Browser instances which might cause unexpected behavior or errors including crash in Chromium engine.