NetworkSession#
Added in version 2.40.
Superclasses: Object
Manages network configuration.
Constructors#
- class NetworkSession
- classmethod new(data_directory: str | None = None, cache_directory: str | None = None) NetworkSession #
Creates a new
NetworkSession
with a persistentWebsiteDataManager
. The parametersdata_directory
andcache_directory
will be used as construct properties of theWebsiteDataManager
of the network session. Note that ifNone
is passed, the default directory will be passed toWebsiteDataManager
so thatget_base_data_directory()
andget_base_cache_directory()
always return a value for non ephemeral sessions.It must be passed as construct parameter of a
WebView
.Added in version 2.40.
- Parameters:
data_directory – a base directory for data, or
None
cache_directory – a base directory for caches, or
None
- classmethod new_ephemeral() NetworkSession #
Creates a new
NetworkSession
with an ephemeralWebsiteDataManager
.Added in version 2.40.
Methods#
- class NetworkSession
- allow_tls_certificate_for_host(certificate: TlsCertificate, host: str) None #
Ignore further TLS errors on the
host
for the certificate present ininfo
.If
host
is an IPv6 address, it should not be surrounded by brackets. This expectation matchesget_host()
.Added in version 2.40.
- Parameters:
certificate – a
TlsCertificate
host – the host for which a certificate is to be allowed
- download_uri(uri: str) Download #
Requests downloading of the specified URI string.
The download operation will not be associated to any
WebView
, if you are interested in starting a download from a particularWebView
usedownload_uri()
instead.Added in version 2.40.
- Parameters:
uri – the URI to download
- get_cookie_manager() CookieManager #
Get the
CookieManager
ofsession
.Added in version 2.40.
- classmethod get_default() NetworkSession #
Get the default network session. The default network session is created using
new()
and passingNone
as data and cache directories.Added in version 2.40.
- get_itp_enabled() bool #
Get whether Intelligent Tracking Prevention (ITP) is enabled or not.
Added in version 2.40.
- get_itp_summary(cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None #
Asynchronously get the list of
ITPThirdParty
seen forsession
.Every
ITPThirdParty
contains the list ofITPFirstParty
under which it has been seen.When the operation is finished,
callback
will be called. You can then callget_itp_summary_finish()
to get the result of the operation.Added in version 2.40.
- 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_itp_summary_finish(result: AsyncResult) list[ITPThirdParty] #
Finish an asynchronous operation started with
get_itp_summary()
.Added in version 2.40.
- Parameters:
result – a
AsyncResult
- get_persistent_credential_storage_enabled() bool #
Get whether persistent credential storage is enabled or not.
See also
set_persistent_credential_storage_enabled()
.Added in version 2.40.
- get_tls_errors_policy() TLSErrorsPolicy #
Get the TLS errors policy of
session
.Added in version 2.40.
- get_website_data_manager() WebsiteDataManager #
Get the
WebsiteDataManager
ofsession
.Added in version 2.40.
- is_ephemeral() bool #
Get whether
session
is ephemeral. ANetworkSession
is ephemeral when itsWebsiteDataManager
is ephemeral. SeeWebsiteDataManager
:is-ephemeral for more details.Added in version 2.40.
- prefetch_dns(hostname: str) None #
Resolve the domain name of the given
hostname
in advance, so that if a URI ofhostname
is requested the load will be performed more quickly.Added in version 2.40.
- Parameters:
hostname – a hostname to be resolved
- set_itp_enabled(enabled: bool) None #
Enable or disable Intelligent Tracking Prevention (ITP).
When ITP is enabled resource load statistics are collected and used to decide whether to allow or block third-party cookies and prevent user tracking. Note that while ITP is enabled the accept policy
NO_THIRD_PARTY
is ignored andALWAYS
is used instead. See also webkit_cookie_session_set_accept_policy().Added in version 2.40.
- Parameters:
enabled – value to set
- classmethod set_memory_pressure_settings() None #
Sets
settings
as theMemoryPressureSettings
.Sets
settings
as theMemoryPressureSettings
to be used by the network process created by any instance ofNetworkSession
after this function is called.Be sure to call this function before creating any
NetworkSession
.The periodic check for used memory is disabled by default on network processes. This will be enabled only if custom settings have been set using this function. After that, in order to remove the custom settings and disable the periodic check, this function must be called passing
None
as the value ofsettings
.Added in version 2.40.
- set_persistent_credential_storage_enabled(enabled: bool) None #
Enable or disable persistent credential storage.
When enabled, which is the default for non-ephemeral sessions, the network process will try to read and write HTTP authentiacation credentials from persistent storage.
Added in version 2.40.
- Parameters:
enabled – value to set
- set_proxy_settings(proxy_mode: NetworkProxyMode, proxy_settings: NetworkProxySettings | None = None) None #
Set the network proxy settings to be used by connections started in
session
session.By default
DEFAULT
is used, which means that the system settings will be used (get_default()
). If you want to override the system default settings, you can either useNO_PROXY
to make sure no proxies are used at all, orCUSTOM
to provide your own proxy settings. Whenproxy_mode
isCUSTOM
proxy_settings
must be a validNetworkProxySettings
; otherwise,proxy_settings
must beNone
.Added in version 2.40.
- Parameters:
proxy_mode – a
NetworkProxyMode
proxy_settings – a
NetworkProxySettings
, orNone
- set_tls_errors_policy(policy: TLSErrorsPolicy) None #
Set the TLS errors policy of
session
aspolicy
.Added in version 2.40.
- Parameters:
policy – a
TLSErrorsPolicy