Interface CookieStore

All Superinterfaces:
ProfileService

public interface CookieStore extends ProfileService
A service that allows working with the session and persistent cookies.

Cookies can be stored in the process memory (session cookies) or on the file system (persistent cookies). The service provides access to both the session and persistent cookies.

The persistent cookies are stored in the user data directory. You can configure the user data directory path via the EngineOptions.Builder.userDataDir(Path) method. For example:

 Engine engine = Engine.newInstance(EngineOptions.newBuilder(renderingMode)
         .userDataDir(Paths.get("/Users/MyApp/Data"))
         .build());

All the changes to the cookie store are made in memory, so when you restart the application you will not see the changes you made with the persistent cookies if you do not invoke the persist() method before application exit.

  • Method Summary

    Modifier and Type
    Method
    Description
    Returns an immutable list of all the cookies available in the cookie store.
    Returns an immutable list of cookies for the given url.
    void
    delete(Cookie cookie)
    Deletes the given cookie from the cookie store.
    int
    Deletes all the cookies from the cookie store and returns the number of deleted cookies.
    void
    Persists all the changes performed to the cookie store.
    void
    set(Cookie cookie)
    Sets the cookie.

    Methods inherited from interface com.teamdev.jxbrowser.profile.ProfileService

    profile
  • Method Details

    • cookies

      List<Cookie> cookies()
      Returns an immutable list of all the cookies available in the cookie store. The list includes both the persistent and session cookies.

      The returned cookies are ordered by longest path, then by earliest creation time. Can be empty if there are no cookies in the cookie store.

      Throws:
      ObjectClosedException - when the profile is deleted or its engine is closed
    • cookies

      List<Cookie> cookies(String url)
      Returns an immutable list of cookies for the given url.

      The list includes both the persistent and session cookies.

      The returned cookies are ordered by longest path, then by earliest creation time. Can be empty if there are no cookies associated with the given URL in the cookie store.

      Parameters:
      url - the URL of the resource to get cookies from
      Throws:
      IllegalArgumentException - when url is empty or blank
      ObjectClosedException - when the profile is deleted or its engine is closed
    • delete

      void delete(Cookie cookie)
      Deletes the given cookie from the cookie store.

      Important: this method makes the cookie changes in memory. To keep these changes for the persistent cookies after application restart you must invoke the persist() method before application exit.

      Parameters:
      cookie - a Cookie instance to delete
      Throws:
      ObjectClosedException - when the profile is deleted or its engine is closed
    • deleteAll

      int deleteAll()
      Deletes all the cookies from the cookie store and returns the number of deleted cookies.

      Important: this method makes the cookie changes in memory. To keep these changes for persistent cookies after application restart you must invoke the persist() method before application exit.

      Throws:
      ObjectClosedException - when the profile is deleted or its engine is closed
    • set

      void set(Cookie cookie)
      Sets the cookie.

      This method expects that each cookie attribute in the given cookie is well-formed.

      Please note that Chromium may modify some of the cookie attributes (such as domain or expiration time).

      Important: this method makes the cookie changes in memory. To keep these changes for the persistent cookies after the application restart invoke the persist() method before the application exit.

      Parameters:
      cookie - a cookie to set
      Throws:
      IllegalArgumentException - when the cookie can't be set
      ObjectClosedException - when the profile is deleted or its engine is closed
    • persist

      void persist()
      Persists all the changes performed to the cookie store.

      By default, all the changes to the cookie store are made in memory, so when you restart the application you will not see the changes you made with persistent cookies if you do not invoke this method before application exit.

      This method can be invoked after every change you made to the cookie store.

      Throws:
      ObjectClosedException - when the profile is deleted or its engine is closed