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
NetworkSessionwith a persistentWebsiteDataManager. The parametersdata_directoryandcache_directorywill be used as construct properties of theWebsiteDataManagerof the network session. Note that ifNoneis passed, the default directory will be passed toWebsiteDataManagerso 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
Nonecache_directory – a base directory for caches, or
None
- classmethod new_ephemeral() NetworkSession#
Creates a new
NetworkSessionwith 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
hostfor the certificate present ininfo.If
hostis an IPv6 address, it should not be surrounded by brackets. This expectation matchesget_host().Added in version 2.40.
- Parameters:
certificate – a
TlsCertificatehost – 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 particularWebViewusedownload_uri()instead.Added in version 2.40.
- Parameters:
uri – the URI to download
- get_cookie_manager() CookieManager#
Get the
CookieManagerofsession.Added in version 2.40.
- classmethod get_default() NetworkSession#
Get the default network session. The default network session is created using
new()and passingNoneas 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.
- async get_itp_summary(self) list[ITPThirdParty]#
This is the awaitable version of
get_itp_summary().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
ITPThirdPartyseen forsession.Every
ITPThirdPartycontains the list ofITPFirstPartyunder which it has been seen.When the operation is finished,
callbackwill be called. You can then callget_itp_summary_finish()to get the result of the operation.Added in version 2.40.
- Parameters:
cancellable – a
CancellableorNoneto ignorecallback – a
AsyncReadyCallbackto 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
WebsiteDataManagerofsession.Added in version 2.40.
- is_ephemeral() bool#
Get whether
sessionis ephemeral. ANetworkSessionis ephemeral when itsWebsiteDataManageris ephemeral. SeeWebsiteDataManager:is-ephemeral for more details.Added in version 2.40.
- prefetch_dns(hostname: str) None#
Resolve the domain name of the given
hostnamein advance, so that if a URI ofhostnameis 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_PARTYis ignored andALWAYSis 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
settingsas theMemoryPressureSettings.Sets
settingsas theMemoryPressureSettingsto be used by the network process created by any instance ofNetworkSessionafter 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
Noneas 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
sessionsession.By default
DEFAULTis 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_PROXYto make sure no proxies are used at all, orCUSTOMto provide your own proxy settings. Whenproxy_modeisCUSTOMproxy_settingsmust be a validNetworkProxySettings; otherwise,proxy_settingsmust beNone.Added in version 2.40.
- Parameters:
proxy_mode – a
NetworkProxyModeproxy_settings – a
NetworkProxySettings, orNone
- set_tls_errors_policy(policy: TLSErrorsPolicy) None#
Set the TLS errors policy of
sessionaspolicy.Added in version 2.40.
- Parameters:
policy – a
TLSErrorsPolicy