iblqt.core.RestrictedWebEnginePage

class iblqt.core.RestrictedWebEnginePage[source]

Bases: QWebEnginePage

A QWebEnginePage subclass that filters navigation requests based on a URL prefix.

Links that start with the specified trusted_url_prefix are allowed to load inside the application. All other links are opened externally in the default web browser.

Adapted from: https://www.pythonguis.com/faq/qwebengineview-open-links-new-window/

__init__(parent=None, trusted_url_prefix='')[source]

Initialize the UrlFilteredWebEnginePage.

Parameters:
  • parent (QObject, optional) – The parent of this web engine page.

  • trusted_url_prefix (str) – A URL prefix that identifies trusted links. Only links starting with this prefix will be loaded within the web view.

acceptNavigationRequest(url, navigationType, is_main_frame)[source]

Handle and filter navigation requests.

Parameters:
  • url (QUrl) – The target URL of the navigation request.

  • navigationType (NavigationType) – The type of navigation event

  • is_main_frame (bool) – Whether the navigation occurs in the main frame.

Returns:

True if the navigation should proceed in the web view; False if the link is handled externally.

Return type:

bool

setTrustedUrlPrefix(trusted_url_prefix)[source]

Set the URL prefix that identifies trusted links.

Parameters:

trusted_url_prefix (str) – The URL prefix that identifies trusted links.

Return type:

None

trustedUrlPrefix()[source]

Retrieve the URL prefix that identifies trusted links.

Returns:

The URL prefix that identifies trusted links.

Return type:

str