NetworkSession

Added in version 2.40.

class NetworkSession(**properties: Any)

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 persistent WebsiteDataManager. The parameters data_directory and cache_directory will be used as construct properties of the WebsiteDataManager of the network session. Note that if None is passed, the default directory will be passed to WebsiteDataManager so that get_base_data_directory() and get_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 ephemeral WebsiteDataManager.

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 in info.

If host is an IPv6 address, it should not be surrounded by brackets. This expectation matches get_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 particular WebView use download_uri() instead.

Added in version 2.40.

Parameters:

uri – the URI to download

Get the CookieManager of session.

Added in version 2.40.

get_default() NetworkSession

Get the default network session. The default network session is created using new() and passing None 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[[...], None] | None = None, *user_data: Any) None

Asynchronously get the list of ITPThirdParty seen for session.

Every ITPThirdParty contains the list of ITPFirstParty under which it has been seen.

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

Added in version 2.40.

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_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 of session.

Added in version 2.40.

is_ephemeral() bool

Get whether session is ephemeral. A NetworkSession is ephemeral when its WebsiteDataManager is ephemeral. See WebsiteDataManager: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 of hostname 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 and ALWAYS is used instead. See also webkit_cookie_session_set_accept_policy().

Added in version 2.40.

Parameters:

enabled – value to set

set_memory_pressure_settings(settings: MemoryPressureSettings) None

Sets settings as the MemoryPressureSettings.

Sets settings as the MemoryPressureSettings to be used by the network process created by any instance of NetworkSession 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 of settings.

Added in version 2.40.

Parameters:

settings – a WebKitMemoryPressureSettings.

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 use NO_PROXY to make sure no proxies are used at all, or CUSTOM to provide your own proxy settings. When proxy_mode is CUSTOM proxy_settings must be a valid NetworkProxySettings; otherwise, proxy_settings must be None.

Added in version 2.40.

Parameters:
set_tls_errors_policy(policy: TLSErrorsPolicy) None

Set the TLS errors policy of session as policy.

Added in version 2.40.

Parameters:

policy – a TLSErrorsPolicy

Properties

class NetworkSession
props.cache_directory: str

The base caches directory used to create the WebsiteDataManager. If None, a default location will be used.

Added in version 2.40.

props.data_directory: str

The base data directory used to create the WebsiteDataManager. If None, a default location will be used.

Added in version 2.40.

props.is_ephemeral: bool

Whether to create an ephermeral WebsiteDataManager for the session.

Added in version 2.40.

Signals

class NetworkSession.signals
download_started(download: Download) None

This signal is emitted when a new download request is made.

Added in version 2.40.

Parameters:

download – the Download associated with this event