CookieManager

class CookieManager(**properties: Any)

Superclasses: Object

Defines how to handle cookies in a WebContext.

The WebKitCookieManager defines how to set up and handle cookies. You can get it from a WebsiteDataManager with webkit_website_data_manager_get_cookie_manager(), and use it to set where to store cookies with set_persistent_storage(), or to set the acceptance policy, with get_accept_policy().

Methods

class CookieManager

Asynchronously add a Cookie to the underlying storage.

When the operation is finished, callback will be called. You can then call add_cookie_finish() to get the result of the operation.

Added in version 2.20.

Parameters:
  • cookie – the Cookie to be added

  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when the request is satisfied

  • user_data – the data to pass to callback function

Finish an asynchronous operation started with add_cookie().

Added in version 2.20.

Parameters:

result – a AsyncResult

Asynchronously delete a Cookie from the current session.

When the operation is finished, callback will be called. You can then call delete_cookie_finish() to get the result of the operation.

Added in version 2.20.

Parameters:
  • cookie – the Cookie to be deleted

  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when the request is satisfied

  • user_data – the data to pass to callback function

Finish an asynchronous operation started with delete_cookie().

Added in version 2.20.

Parameters:

result – a AsyncResult

get_accept_policy(cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronously get the cookie acceptance policy of cookie_manager.

Note that when policy was set to NO_THIRD_PARTY and ITP is enabled, this will return ALWAYS. See also webkit_website_data_manager_set_itp_enabled().

When the operation is finished, callback will be called. You can then call get_accept_policy_finish() to get the result of the operation.

Parameters:
  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when the request is satisfied

  • user_data – the data to pass to callback function

get_accept_policy_finish(result: AsyncResult) CookieAcceptPolicy

Finish an asynchronous operation started with get_accept_policy().

Parameters:

result – a AsyncResult

get_all_cookies(cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronously get a list of Cookie from cookie_manager.

When the operation is finished, callback will be called. You can then call get_all_cookies_finish() to get the result of the operation.

Added in version 2.42.

Parameters:
  • cancellable – a Cancellable or None to ignore

  • callback – (closure user_data): a AsyncReadyCallback to call when the request is satisfied

  • user_data – the data to pass to callback function

get_all_cookies_finish(result: AsyncResult) list[Cookie]

Finish an asynchronous operation started with get_all_cookies().

The return value is a List of Cookie instances which should be released with free_full() and free().

Added in version 2.42.

Parameters:

result – a AsyncResult

get_cookies(uri: str, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronously get a list of Cookie from cookie_manager.

Asynchronously get a list of Cookie from cookie_manager associated with uri, which must be either an HTTP or an HTTPS URL.

When the operation is finished, callback will be called. You can then call get_cookies_finish() to get the result of the operation.

Added in version 2.20.

Parameters:
  • uri – the URI associated to the cookies to be retrieved

  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when the request is satisfied

  • user_data – the data to pass to callback function

get_cookies_finish(result: AsyncResult) list[Cookie]

Finish an asynchronous operation started with get_cookies().

The return value is a List of Cookie instances which should be released with free_full() and free().

Added in version 2.20.

Parameters:

result – a AsyncResult

replace_cookies(cookies: list[Cookie], cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronously replace all cookies in cookie_manager with the given list of cookies.

When the operation is finished, callback will be called. You can then call replace_cookies_finish() to get the result of the operation.

Added in version 2.42.

Parameters:
  • cookies – a List of Cookie to be added

  • cancellable – a Cancellable or None to ignore

  • callback – (closure user_data): a AsyncReadyCallback to call when the request is satisfied

  • user_data – the data to pass to callback function

replace_cookies_finish(result: AsyncResult) bool

Finish an asynchronous operation started with replace_cookies().

Added in version 2.42.

Parameters:

result – a AsyncResult

set_accept_policy(policy: CookieAcceptPolicy) None

Set the cookie acceptance policy of cookie_manager as policy.

Note that ITP has its own way to handle third-party cookies, so when it’s enabled, and policy is set to NO_THIRD_PARTY, ALWAYS will be used instead. Once disabled, the policy will be set back to NO_THIRD_PARTY. See also webkit_website_data_manager_set_itp_enabled().

Parameters:

policy – a CookieAcceptPolicy

set_persistent_storage(filename: str, storage: CookiePersistentStorage) None

Set non-session cookies.

Set the filename where non-session cookies are stored persistently using storage as the format to read/write the cookies. Cookies are initially read from filename to create an initial set of cookies. Then, non-session cookies will be written to filename when the WebKitCookieManager::changed signal is emitted. By default, cookie_manager doesn’t store the cookies persistently, so you need to call this method to keep cookies saved across sessions.

This method should never be called on a CookieManager associated to an ephemeral WebsiteDataManager.

Parameters:

Signals

class CookieManager.signals
changed() None

This signal is emitted when cookies are added, removed or modified.