:right-sidebar: True NetworkSession =================================================================== .. currentmodule:: gi.repository.WebKit .. versionadded:: 2.40 .. class:: NetworkSession(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Manages network configuration. Constructors ------------ .. rst-class:: interim-class .. class:: NetworkSession :no-index: .. classmethod:: new(data_directory: str | None = None, cache_directory: str | None = None) -> ~gi.repository.WebKit.NetworkSession Creates a new :obj:`~gi.repository.WebKit.NetworkSession` with a persistent :obj:`~gi.repository.WebKit.WebsiteDataManager`. The parameters ``data_directory`` and ``cache_directory`` will be used as construct properties of the :obj:`~gi.repository.WebKit.WebsiteDataManager` of the network session. Note that if :const:`None` is passed, the default directory will be passed to :obj:`~gi.repository.WebKit.WebsiteDataManager` so that :func:`~gi.repository.WebKit.WebsiteDataManager.get_base_data_directory` and :func:`~gi.repository.WebKit.WebsiteDataManager.get_base_cache_directory` always return a value for non ephemeral sessions. It must be passed as construct parameter of a :obj:`~gi.repository.WebKit.WebView`. .. versionadded:: 2.40 :param data_directory: a base directory for data, or :const:`None` :param cache_directory: a base directory for caches, or :const:`None` .. classmethod:: new_ephemeral() -> ~gi.repository.WebKit.NetworkSession Creates a new :obj:`~gi.repository.WebKit.NetworkSession` with an ephemeral :obj:`~gi.repository.WebKit.WebsiteDataManager`. .. versionadded:: 2.40 Methods ------- .. rst-class:: interim-class .. class:: NetworkSession :no-index: .. method:: allow_tls_certificate_for_host(certificate: ~gi.repository.Gio.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 :func:`~gi.repository.GLib.Uri.get_host`. .. versionadded:: 2.40 :param certificate: a :obj:`~gi.repository.Gio.TlsCertificate` :param host: the host for which a certificate is to be allowed .. method:: download_uri(uri: str) -> ~gi.repository.WebKit.Download Requests downloading of the specified URI string. The download operation will not be associated to any :obj:`~gi.repository.WebKit.WebView`, if you are interested in starting a download from a particular :obj:`~gi.repository.WebKit.WebView` use :func:`~gi.repository.WebKit.WebView.download_uri` instead. .. versionadded:: 2.40 :param uri: the URI to download .. method:: get_cookie_manager() -> ~gi.repository.WebKit.CookieManager Get the :obj:`~gi.repository.WebKit.CookieManager` of ``session``. .. versionadded:: 2.40 .. method:: get_default() -> ~gi.repository.WebKit.NetworkSession Get the default network session. The default network session is created using :func:`~gi.repository.WebKit.NetworkSession.new` and passing :const:`None` as data and cache directories. .. versionadded:: 2.40 .. method:: get_itp_enabled() -> bool Get whether Intelligent Tracking Prevention (ITP) is enabled or not. .. versionadded:: 2.40 .. method:: get_itp_summary(cancellable: ~gi.repository.Gio.Cancellable | None = None, callback: ~typing.Callable[[...], None] | None = None, *user_data: ~typing.Any) -> None Asynchronously get the list of :obj:`~gi.repository.WebKit.ITPThirdParty` seen for ``session``. Every :obj:`~gi.repository.WebKit.ITPThirdParty` contains the list of :obj:`~gi.repository.WebKit.ITPFirstParty` under which it has been seen. When the operation is finished, ``callback`` will be called. You can then call :func:`~gi.repository.WebKit.NetworkSession.get_itp_summary_finish` to get the result of the operation. .. versionadded:: 2.40 :param cancellable: a :obj:`~gi.repository.Gio.Cancellable` or :const:`None` to ignore :param callback: a :obj:`~gi.repository.Gio.AsyncReadyCallback` to call when the request is satisfied :param user_data: the data to pass to callback function .. method:: get_itp_summary_finish(result: ~gi.repository.Gio.AsyncResult) -> list[~gi.repository.WebKit.ITPThirdParty] Finish an asynchronous operation started with :func:`~gi.repository.WebKit.NetworkSession.get_itp_summary`. .. versionadded:: 2.40 :param result: a :obj:`~gi.repository.Gio.AsyncResult` .. method:: get_persistent_credential_storage_enabled() -> bool Get whether persistent credential storage is enabled or not. See also :func:`~gi.repository.WebKit.NetworkSession.set_persistent_credential_storage_enabled`. .. versionadded:: 2.40 .. method:: get_tls_errors_policy() -> ~gi.repository.WebKit.TLSErrorsPolicy Get the TLS errors policy of ``session``. .. versionadded:: 2.40 .. method:: get_website_data_manager() -> ~gi.repository.WebKit.WebsiteDataManager Get the :obj:`~gi.repository.WebKit.WebsiteDataManager` of ``session``. .. versionadded:: 2.40 .. method:: is_ephemeral() -> bool Get whether ``session`` is ephemeral. A :obj:`~gi.repository.WebKit.NetworkSession` is ephemeral when its :obj:`~gi.repository.WebKit.WebsiteDataManager` is ephemeral. See :obj:`~gi.repository.WebKit.WebsiteDataManager`:is-ephemeral for more details. .. versionadded:: 2.40 .. method:: 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. .. versionadded:: 2.40 :param hostname: a hostname to be resolved .. method:: 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 :const:`~gi.repository.WebKit.CookieAcceptPolicy.NO_THIRD_PARTY` is ignored and :const:`~gi.repository.WebKit.CookieAcceptPolicy.ALWAYS` is used instead. See also webkit_cookie_session_set_accept_policy(). .. versionadded:: 2.40 :param enabled: value to set .. method:: set_memory_pressure_settings(settings: ~gi.repository.WebKit.MemoryPressureSettings) -> None Sets ``settings`` as the :obj:`~gi.repository.WebKit.MemoryPressureSettings`. Sets ``settings`` as the :obj:`~gi.repository.WebKit.MemoryPressureSettings` to be used by the network process created by any instance of :obj:`~gi.repository.WebKit.NetworkSession` after this function is called. Be sure to call this function before creating any :obj:`~gi.repository.WebKit.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 :const:`None` as the value of ``settings``. .. versionadded:: 2.40 :param settings: a WebKitMemoryPressureSettings. .. method:: 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. .. versionadded:: 2.40 :param enabled: value to set .. method:: set_proxy_settings(proxy_mode: ~gi.repository.WebKit.NetworkProxyMode, proxy_settings: ~gi.repository.WebKit.NetworkProxySettings | None = None) -> None Set the network proxy settings to be used by connections started in ``session`` session. By default :const:`~gi.repository.WebKit.NetworkProxyMode.DEFAULT` is used, which means that the system settings will be used (:func:`~gi.repository.Gio.ProxyResolver.get_default`). If you want to override the system default settings, you can either use :const:`~gi.repository.WebKit.NetworkProxyMode.NO_PROXY` to make sure no proxies are used at all, or :const:`~gi.repository.WebKit.NetworkProxyMode.CUSTOM` to provide your own proxy settings. When ``proxy_mode`` is :const:`~gi.repository.WebKit.NetworkProxyMode.CUSTOM` ``proxy_settings`` must be a valid :obj:`~gi.repository.WebKit.NetworkProxySettings`; otherwise, ``proxy_settings`` must be :const:`None`. .. versionadded:: 2.40 :param proxy_mode: a :obj:`~gi.repository.WebKit.NetworkProxyMode` :param proxy_settings: a :obj:`~gi.repository.WebKit.NetworkProxySettings`, or :const:`None` .. method:: set_tls_errors_policy(policy: ~gi.repository.WebKit.TLSErrorsPolicy) -> None Set the TLS errors policy of ``session`` as ``policy``. .. versionadded:: 2.40 :param policy: a :obj:`~gi.repository.WebKit.TLSErrorsPolicy` Properties ---------- .. rst-class:: interim-class .. class:: NetworkSession :no-index: .. attribute:: props.cache_directory :type: str The base caches directory used to create the :obj:`~gi.repository.WebKit.WebsiteDataManager`. If :const:`None`, a default location will be used. .. versionadded:: 2.40 .. attribute:: props.data_directory :type: str The base data directory used to create the :obj:`~gi.repository.WebKit.WebsiteDataManager`. If :const:`None`, a default location will be used. .. versionadded:: 2.40 .. attribute:: props.is_ephemeral :type: bool Whether to create an ephermeral :obj:`~gi.repository.WebKit.WebsiteDataManager` for the session. .. versionadded:: 2.40 Signals ------- .. rst-class:: interim-class .. class:: NetworkSession.signals :no-index: .. method:: download_started(download: ~gi.repository.WebKit.Download) -> None This signal is emitted when a new download request is made. .. versionadded:: 2.40 :param download: the :obj:`~gi.repository.WebKit.Download` associated with this event