CookieManager#
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
- add_cookie(cookie: Cookie, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) → None#
Asynchronously add a
Cookie
to the underlying storage.When the operation is finished,
callback
will be called. You can then calladd_cookie_finish()
to get the result of the operation.Added in version 2.20.
- Parameters:
cookie – the
Cookie
to be addedcancellable – a
Cancellable
orNone
to ignorecallback – a
AsyncReadyCallback
to call when the request is satisfieduser_data – the data to pass to callback function
- add_cookie_finish(result: AsyncResult) → bool#
Finish an asynchronous operation started with
add_cookie()
.Added in version 2.20.
- Parameters:
result – a
AsyncResult
- delete_cookie(cookie: Cookie, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) → None#
Asynchronously delete a
Cookie
from the current session.When the operation is finished,
callback
will be called. You can then calldelete_cookie_finish()
to get the result of the operation.Added in version 2.20.
- Parameters:
cookie – the
Cookie
to be deletedcancellable – a
Cancellable
orNone
to ignorecallback – a
AsyncReadyCallback
to call when the request is satisfieduser_data – the data to pass to callback function
- delete_cookie_finish(result: AsyncResult) → bool#
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[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) → 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 returnALWAYS
. See also webkit_website_data_manager_set_itp_enabled().When the operation is finished,
callback
will be called. You can then callget_accept_policy_finish()
to get the result of the operation.- Parameters:
cancellable – a
Cancellable
orNone
to ignorecallback – a
AsyncReadyCallback
to call when the request is satisfieduser_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[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) → None#
Asynchronously get a list of
Cookie
fromcookie_manager
.When the operation is finished,
callback
will be called. You can then callget_all_cookies_finish()
to get the result of the operation.Added in version 2.42.
- Parameters:
cancellable – a
Cancellable
orNone
to ignorecallback – (closure user_data): a
AsyncReadyCallback
to call when the request is satisfieduser_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
ofCookie
instances which should be released withfree_full()
andfree()
.Added in version 2.42.
- Parameters:
result – a
AsyncResult
- get_cookies(uri: str, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) → None#
Asynchronously get a list of
Cookie
fromcookie_manager
.Asynchronously get a list of
Cookie
fromcookie_manager
associated withuri
, which must be either an HTTP or an HTTPS URL.When the operation is finished,
callback
will be called. You can then callget_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
orNone
to ignorecallback – a
AsyncReadyCallback
to call when the request is satisfieduser_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
ofCookie
instances which should be released withfree_full()
andfree()
.Added in version 2.20.
- Parameters:
result – a
AsyncResult
- replace_cookies(cookies: list[Cookie], cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) → None#
Asynchronously replace all cookies in
cookie_manager
with the given list ofcookies
.When the operation is finished,
callback
will be called. You can then callreplace_cookies_finish()
to get the result of the operation.Added in version 2.42.
- Parameters:
cancellable – a
Cancellable
orNone
to ignorecallback – (closure user_data): a
AsyncReadyCallback
to call when the request is satisfieduser_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
aspolicy
.Note that ITP has its own way to handle third-party cookies, so when it’s enabled, and
policy
is set toNO_THIRD_PARTY
,ALWAYS
will be used instead. Once disabled, the policy will be set back toNO_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 usingstorage
as the format to read/write the cookies. Cookies are initially read fromfilename
to create an initial set of cookies. Then, non-session cookies will be written tofilename
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 ephemeralWebsiteDataManager
.- Parameters:
filename – the filename to read to/write from
storage – a
CookiePersistentStorage