This document describes how to work with cookies.


JxBrowser delegates the work with cookies to the Chromium engine. Chromium decides how to download cookies from a web server, extract them from the HTTP headers and store them in the User Data directory (persistent cookies) or in the memory (session cookies).

The CookieStore class allows you to get, modify, and remove cookies. The Cookie class provides information on a particular cookie.

To obtain the CookieStore for a specific Profile please use the Profile.cookieStore() method. The Engine.cookieStore() method returns the CookieStore associated with the default profile.

To access cookie store use the following way:

CookieStore cookieStore = profile.cookieStore();

Supported Protocols

JxBrowser supports cookies that are sent using the following protocols:

  • HTTP
  • WS (WebSocket)
  • WSS (Secured WebSocket)

If a cookie is sent using a protocol that is not on the list, e.g. ftp://, it will not be stored in the cookie storage.

Working with Cookies

JxBrowser supports the following kinds of cookies:

  • Persistent cookies — these are stored in the Chromium user data directory. If you delete the Chromium user data directory, all the persistent cookies will be removed.
  • Session cookies — these are stored in the application memory. These cookies will be removed automatically when the application is terminated.
  • Secure cookies — these can only be transmitted over an encrypted connection, i.e. HTTPS. This makes the cookie less likely to be exposed to cookie theft via eavesdropping.
  • HttpOnly cookies — these cannot be accessed by the client-side APIs, such as JavaScript. This restriction eliminates the threat of cookie theft via cross-site scripting (XSS). However, the cookie remains vulnerable to cross-site tracing (XST) and cross-site request forgery (XSRF) attacks.

When you modify cookies please use the CookieStore.persist() method to save the changes.

Getting Cookies

To get all cookies, please use the cookies() method:

cookieStore.cookies().forEach(cookie -> 
        System.out.println("cookie = " + cookie));

To get all cookies by a URL, please use the getCookies() method that accepts a string:

cookieStore.cookies("").forEach(cookie -> 
        System.out.println("cookie = " + cookie));

Creating Cookies


To create a persistent cookie with an expiration time use the following code:



To create a session cookie use the following code:


Deleting Cookies

To delete all cookies use the deleteAll() method:

int numberOfDeletedCookies = cookieStore.deleteAll();

To delete one cookie, please use the delete(Cookie). The following code deletes all cookies one by one obtaining the result of the operation:


Suppressing Cookies

You can control all incoming and outgoing cookies using the CanSetCookieCallback and CanGetCookiesCallback callbacks of the Network.

To suppress the incoming cookies use the following code:

network.set(CanSetCookieCallback.class, params -> Response.cannot());

To suppress the outgoing cookies use the following code:

network.set(CanGetCookiesCallback.class, params -> Response.cannot());


JxBrowser supports the cookie encryption by default. It uses the Chromium cookies encryption routines, so the cookies are stored exactly as in Chromium.


On Linux JxBrowser uses GNOME Keyring or KWallet to encrypt cookies. The library automatically chooses which store to use. You can manually specify which store to use via an appropriate option when constructing the Engine. For example:

Engine engine = Engine.newInstance(EngineOptions.newBuilder(...)


On Windows JxBrowser uses only DPAPI to encrypt cookies. There are no alternatives at the moment.


On macOS JxBrowser uses the private key stored with the Keychain Application to encrypt cookies with AES encryption.

Go Top