WebView#

class WebView(**properties: Any)#

Superclasses: WebViewBase, Widget, InitiallyUnowned, Object

Implemented Interfaces: Accessible, Buildable, ConstraintTarget

The central class of the WPE WebKit and WebKitGTK APIs.

WebView is the central class of the WPE WebKit and WebKitGTK APIs. It is responsible for managing the drawing of the content and forwarding of events. You can load any URI into the WebView or a data string. With Settings you can control various aspects of the rendering and loading of the content.

Note that in WebKitGTK, WebView is scrollable by itself, so you don’t need to embed it in a ScrolledWindow.

Constructors#

class WebView
classmethod new() Widget#

Creates a new WebView with the default WebContext.

Creates a new WebView with the default WebContext and no UserContentManager associated with it. See also webkit_web_view_new_with_context(), webkit_web_view_new_with_user_content_manager(), and webkit_web_view_new_with_settings().

Methods#

class WebView
call_async_javascript_function(body: str, length: int, arguments: Variant | None = None, world_name: str | None = None, source_uri: str | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Asynchronously call body with arguments in the script world with name world_name of the main frame current context in web_view. The arguments values must be one of the following types, or contain only the following GVariant types: number, string and dictionary. The result of the operation can be a Promise that will be properly passed to the callback. If world_name is None, the default world is used. Any value that is not None is a distin ct world. The source_uri will be shown in exceptions and doesn’t affect the behavior of the script. When not provided, the document URL is used.

Note that if Settings:enable-javascript is False, this method will do nothing. If you want to use this method but still prevent web content from executing its own JavaScript, then use Settings:enable-javascript-markup.

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

This is an example that shows how to pass arguments to a JS function that returns a Promise that resolves with the passed argument:

static void
web_view_javascript_finished (GObject      *object,
                              GAsyncResult *result,
                              gpointer      user_data)
{
    JSCValue               *value;
    GError                 *error = NULL;

    value = webkit_web_view_call_async_javascript_function_finish (WEBKIT_WEB_VIEW (object), result, &error);
    if (!value) {
        g_warning ("Error running javascript: %s", error->message);
        g_error_free (error);
        return;
    }

    if (jsc_value_is_number (value)) {
        gint32        int_value = jsc_value_to_string (value);
        JSCException *exception = jsc_context_get_exception (jsc_value_get_context (value));
        if (exception)
            g_warning ("Error running javascript: %s", jsc_exception_get_message (exception));
        else
            g_print ("Script result: %d\n", int_value);
        g_free (str_value);
    } else {
        g_warning ("Error running javascript: unexpected return value");
    }
    g_object_unref (value);
}

static void
web_view_evaluate_promise (WebKitWebView *web_view)
{
    GVariantDict dict;
    g_variant_dict_init (&dict, NULL);
    g_variant_dict_insert (&dict, "count", "u", 42);
    GVariant *args = g_variant_dict_end (&dict);
    const gchar *body = "return new Promise((resolve) => { resolve(count); });";
    webkit_web_view_call_async_javascript_function (web_view, body, -1, arguments, NULL, NULL, NULL, web_view_javascript_finished, NULL);
}

Added in version 2.40.

Parameters:
  • body – the function body

  • length – length of body, or -1 if body is a nul-terminated string

  • arguments – a Variant with format a{sv} storing the function arguments, or None

  • world_name – the name of a WebKitScriptWorld or None to use the default

  • source_uri – the source URI

  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when the script finished

  • user_data – the data to pass to callback function

call_async_javascript_function_finish(result: AsyncResult) Value#

Finish an asynchronous operation started with call_async_javascript_function().

Added in version 2.40.

Parameters:

result – a AsyncResult

can_execute_editing_command(command: str, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Asynchronously check if it is possible to execute the given editing command.

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

Parameters:
  • command – the command to check

  • 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

can_execute_editing_command_finish(result: AsyncResult) bool#

Finish an asynchronous operation started with can_execute_editing_command().

Parameters:

result – a AsyncResult

can_go_back() bool#

Determines whether web_view has a previous history item.

can_go_forward() bool#

Determines whether web_view has a next history item.

can_show_mime_type(mime_type: str) bool#

Whether or not a MIME type can be displayed in web_view.

Parameters:

mime_type – a MIME type

do_authenticate(self, request: AuthenticationRequest) bool#
Parameters:

request

do_close(self) None#
do_context_menu(self, context_menu: ContextMenu, hit_test_result: HitTestResult) bool#
Parameters:
  • context_menu

  • hit_test_result

do_context_menu_dismissed(self) None#
do_decide_policy(self, decision: PolicyDecision, type: PolicyDecisionType) bool#
Parameters:
  • decision

  • type

do_enter_fullscreen(self) bool#
do_insecure_content_detected(self, event: InsecureContentEvent) None#
Parameters:

event

do_leave_fullscreen(self) bool#
do_load_changed(self, load_event: LoadEvent) None#
Parameters:

load_event

do_load_failed(self, load_event: LoadEvent, failing_uri: str, error: GError) bool#
Parameters:
  • load_event

  • failing_uri

  • error

do_load_failed_with_tls_errors(self, failing_uri: str, certificate: TlsCertificate, errors: TlsCertificateFlags) bool#
Parameters:
  • failing_uri

  • certificate

  • errors

do_mouse_target_changed(self, hit_test_result: HitTestResult, modifiers: int) None#
Parameters:
  • hit_test_result

  • modifiers

do_permission_request(self, permission_request: PermissionRequest) bool#
Parameters:

permission_request

do_print_(self, print_operation: PrintOperation) bool#
Parameters:

print_operation

do_query_permission_state(self, query: PermissionStateQuery) bool#
Parameters:

query

do_ready_to_show(self) None#
do_resource_load_started(self, resource: WebResource, request: URIRequest) None#
Parameters:
  • resource

  • request

do_run_as_modal(self) None#
do_run_color_chooser(self, request: ColorChooserRequest) bool#
Parameters:

request

do_run_file_chooser(self, request: FileChooserRequest) bool#
Parameters:

request

do_script_dialog(self, dialog: ScriptDialog) bool#
Parameters:

dialog

do_show_notification(self, notification: Notification) bool#
Parameters:

notification

do_show_option_menu(self, menu: OptionMenu, rectangle: Rectangle) bool#
Parameters:
  • menu

  • rectangle

do_submit_form(self, request: FormSubmissionRequest) None#
Parameters:

request

do_user_message_received(self, message: UserMessage) bool#
Parameters:

message

do_web_process_crashed(self) bool#
do_web_process_terminated(self, reason: WebProcessTerminationReason) None#
Parameters:

reason

download_uri(uri: str) Download#

Requests downloading of the specified URI string for web_view.

Parameters:

uri – the URI to download

evaluate_javascript(script: str, length: int, world_name: str | None = None, source_uri: str | None = None, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Asynchronously evaluate script in the script world with name world_name of the main frame current context in web_view. If world_name is None, the default world is used. Any value that is not None is a distinct world. The source_uri will be shown in exceptions and doesn’t affect the behavior of the script. When not provided, the document URL is used.

Note that if Settings:enable-javascript is False, this method will do nothing. If you want to use this method but still prevent web content from executing its own JavaScript, then use Settings:enable-javascript-markup.

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

This is an example of using evaluate_javascript() with a script returning a string:

static void
web_view_javascript_finished (GObject      *object,
                              GAsyncResult *result,
                              gpointer      user_data)
{
    JSCValue               *value;
    GError                 *error = NULL;

    value = webkit_web_view_evaluate_javascript_finish (WEBKIT_WEB_VIEW (object), result, &error);
    if (!value) {
        g_warning ("Error running javascript: %s", error->message);
        g_error_free (error);
        return;
    }

    if (jsc_value_is_string (value)) {
        gchar        *str_value = jsc_value_to_string (value);
        JSCException *exception = jsc_context_get_exception (jsc_value_get_context (value));
        if (exception)
            g_warning ("Error running javascript: %s", jsc_exception_get_message (exception));
        else
            g_print ("Script result: %s\n", str_value);
        g_free (str_value);
    } else {
        g_warning ("Error running javascript: unexpected return value");
    }
    g_object_unref (value);
}

static void
web_view_get_link_url (WebKitWebView *web_view,
                       const gchar   *link_id)
{
    gchar *script = g_strdup_printf ("window.document.getElementById('%s').href;", link_id);
    webkit_web_view_evaluate_javascript (web_view, script, -1, NULL, NULL, NULL, web_view_javascript_finished, NULL);
    g_free (script);
}

Added in version 2.40.

Parameters:
  • script – the script to evaluate

  • length – length of script, or -1 if script is a nul-terminated string

  • world_name – the name of a WebKitScriptWorld or None to use the default

  • source_uri – the source URI

  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when the script finished

  • user_data – the data to pass to callback function

evaluate_javascript_finish(result: AsyncResult) Value#

Finish an asynchronous operation started with evaluate_javascript().

Added in version 2.40.

Parameters:

result – a AsyncResult

execute_editing_command(command: str) None#

Request to execute the given command for web_view.

You can use can_execute_editing_command() to check whether it’s possible to execute the command.

Parameters:

command – the command to execute

execute_editing_command_with_argument(command: str, argument: str) None#

Request to execute the given command with argument for web_view.

You can use can_execute_editing_command() to check whether it’s possible to execute the command.

Added in version 2.10.

Parameters:
  • command – the command to execute

  • argument – the command argument

get_automation_presentation_type() AutomationBrowsingContextPresentation#

Get the presentation type of WebView when created for automation.

Added in version 2.28.

get_back_forward_list() BackForwardList#

Obtains the BackForwardList associated with the given WebView.

The BackForwardList is owned by the WebView.

get_background_color() RGBA#

Gets the color that is used to draw the web_view background.

Gets the color that is used to draw the web_view background before the actual contents are rendered. For more information see also set_background_color()

Added in version 2.8.

get_camera_capture_state() MediaCaptureState#

Get the camera capture state of a WebView.

Added in version 2.34.

get_context() WebContext#

Gets the web context of web_view.

get_custom_charset() str#

Returns the current custom character encoding name of web_view.

get_default_content_security_policy() str | None#

Gets the configured default Content-Security-Policy.

Added in version 2.38.

get_display_capture_state() MediaCaptureState#

Get the display capture state of a WebView.

Added in version 2.34.

get_editor_state() EditorState#

Gets the web editor state of web_view.

Added in version 2.10.

get_estimated_load_progress() float#

Gets the value of the WebView:estimated-load-progress property.

You can monitor the estimated progress of a load operation by connecting to the notify::estimated-load-progress signal of web_view.

get_favicon() Texture#

Returns favicon currently associated to web_view.

Returns favicon currently associated to web_view, if any. You can connect to notify::favicon signal of web_view to be notified when the favicon is available.

get_find_controller() FindController#

Gets the FindController.

Gets the FindController that will allow the caller to query the WebView for the text to look for.

get_input_method_context() InputMethodContext | None#

Get the InputMethodContext currently in use by web_view.

Get the InputMethodContext currently in use by web_view, or None if no input method is being used.

Added in version 2.28.

get_inspector() WebInspector#

Get the WebInspector associated to web_view

get_is_muted() bool#

Gets the mute state of web_view.

Added in version 2.30.

get_is_web_process_responsive() bool#

Get whether the current web process of a WebView is responsive.

Added in version 2.34.

get_main_resource() WebResource#

Return the main resource of web_view.

get_microphone_capture_state() MediaCaptureState#

Get the microphone capture state of a WebView.

Added in version 2.34.

get_network_session() NetworkSession#

Get the NetworkSession associated to web_view.

Added in version 2.40.

get_page_id() int#

Get the identifier of the WebKitWebPage corresponding to the WebView

get_session_state() WebViewSessionState#

Gets the current session state of web_view

Added in version 2.12.

get_settings() Settings#

Gets the Settings currently applied to web_view.

If no other Settings have been explicitly applied to web_view with set_settings(), the default Settings will be returned. This method always returns a valid Settings object. To modify any of the web_view settings, you can either create a new Settings object with new(), setting the desired preferences, and then replace the existing web_view settings with set_settings() or get the existing web_view settings and update it directly. Settings objects can be shared by multiple WebView<!– –>s, so modifying the settings of a WebView would affect other WebView<!– –>s using the same Settings.

get_snapshot(region: SnapshotRegion, options: SnapshotOptions, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Asynchronously retrieves a snapshot of web_view for region.

options specifies how the snapshot should be rendered.

When the operation is finished, callback will be called. You must call get_snapshot_finish() to get the result of the operation.

Parameters:
get_snapshot_finish(result: AsyncResult) Texture#

Finishes an asynchronous operation started with get_snapshot().

Parameters:

result – a AsyncResult

get_title() str#

Gets the value of the WebView:title property.

You can connect to notify::title signal of web_view to be notified when the title has been received.

get_tls_info() Tuple[bool, TlsCertificate, TlsCertificateFlags]#

Retrieves the TlsCertificate associated with the main resource of web_view.

Retrieves the TlsCertificate associated with the main resource of web_view, and the TlsCertificateFlags showing what problems, if any, have been found with that certificate. If the connection is not HTTPS, this function returns False. This function should be called after a response has been received from the server, so you can connect to WebView::load-changed and call this function when it’s emitted with COMMITTED event.

Note that this function provides no information about the security of the web page if the current TLSErrorsPolicy is IGNORE, as subresources of the page may be controlled by an attacker. This function may safely be used to determine the security status of the current page only if the current TLSErrorsPolicy is FAIL, in which case subresources that fail certificate verification will be blocked.

get_uri() str#

Returns the current active URI of web_view.

The active URI might change during a load operation:

<orderedlist> <listitem><para>

When nothing has been loaded yet on web_view the active URI is None.

</para></listitem> <listitem><para>

When a new load operation starts the active URI is the requested URI: <itemizedlist> <listitem><para>

If the load operation was started by load_uri(), the requested URI is the given one.

</para></listitem> <listitem><para>

If the load operation was started by load_html(), the requested URI is “about:blank”.

</para></listitem> <listitem><para>

If the load operation was started by load_alternate_html(), the requested URI is content URI provided.

</para></listitem> <listitem><para>

If the load operation was started by go_back() or go_forward(), the requested URI is the original URI of the previous/next item in the BackForwardList of web_view.

</para></listitem> <listitem><para>

If the load operation was started by go_to_back_forward_list_item(), the requested URI is the opriginal URI of the given BackForwardListItem.

</para></listitem> </itemizedlist>

</para></listitem> <listitem><para>

If there is a server redirection during the load operation, the active URI is the redirected URI. When the signal WebView::load-changed is emitted with REDIRECTED event, the active URI is already updated to the redirected URI.

</para></listitem> <listitem><para>

When the signal WebView::load-changed is emitted with COMMITTED event, the active URI is the final one and it will not change unless a new load operation is started or a navigation action within the same page is performed.

</para></listitem> </orderedlist>

You can monitor the active URI by connecting to the notify::uri signal of web_view.

get_user_content_manager() UserContentManager#

Gets the user content manager associated to web_view.

Added in version 2.6.

get_web_extension_mode() WebExtensionMode#

Get the view’s WebExtensionMode.

Added in version 2.38.

get_website_policies() WebsitePolicies#

Gets the default website policies.

Gets the default website policies set on construction in the web_view. These can be overridden on a per-origin basis via the WebView::decide-policy signal handler.

See also use_with_policies().

Added in version 2.30.

get_window_properties() WindowProperties#

Get the WindowProperties object.

Get the WindowProperties object containing the properties that the window containing web_view should have.

get_zoom_level() float#

Set the zoom level of web_view.

Get the zoom level of web_view, i.e. the factor by which the view contents are scaled with respect to their original size.

go_back() None#

Loads the previous history item.

You can monitor the load operation by connecting to WebView::load-changed signal.

go_forward() None#

Loads the next history item.

You can monitor the load operation by connecting to WebView::load-changed signal.

go_to_back_forward_list_item(list_item: BackForwardListItem) None#

Loads the specific history item list_item.

You can monitor the load operation by connecting to WebView::load-changed signal.

Parameters:

list_item – a BackForwardListItem

is_controlled_by_automation() bool#

Get whether a WebView was created with WebView:is-controlled-by-automation property enabled.

Only WebView<!– –>s controlled by automation can be used in an automation session.

Added in version 2.18.

is_editable() bool#

Gets whether the user is allowed to edit the HTML document.

When web_view is not editable an element in the HTML document can only be edited if the CONTENTEDITABLE attribute has been set on the element or one of its parent elements. By default a WebView is not editable.

Added in version 2.8.

is_loading() bool#

Gets the value of the WebView:is-loading property.

You can monitor when a WebView is loading a page by connecting to notify::is-loading signal of web_view. This is useful when you are interesting in knowing when the view is loading something but not in the details about the status of the load operation, for example to start a spinner when the view is loading a page and stop it when it finishes.

is_playing_audio() bool#

Gets the value of the WebView:is-playing-audio property.

You can monitor when a page in a WebView is playing audio by connecting to the notify::is-playing-audio signal of web_view. This is useful when the application wants to provide visual feedback when a page is producing sound.

Added in version 2.8.

load_alternate_html(content: str, content_uri: str, base_uri: str | None = None) None#

Load the given content string for the URI content_uri.

This allows clients to display page-loading errors in the WebView itself. When this method is called from WebView::load-failed signal to show an error page, then the back-forward list is maintained appropriately. For everything else this method works the same way as load_html().

Parameters:
  • content – the new content to display as the main page of the web_view

  • content_uri – the URI for the alternate page content

  • base_uri – the base URI for relative locations or None

load_bytes(bytes: Bytes, mime_type: str | None = None, encoding: str | None = None, base_uri: str | None = None) None#

Load the specified bytes into web_view using the given mime_type and encoding.

When mime_type is None, it defaults to “text/html”. When encoding is None, it defaults to “UTF-8”. When base_uri is None, it defaults to “about:blank”. You can monitor the load operation by connecting to WebView::load-changed signal.

Added in version 2.6.

Parameters:
  • bytes – input data to load

  • mime_type – the MIME type of bytes, or None

  • encoding – the character encoding of bytes, or None

  • base_uri – the base URI for relative locations or None

load_html(content: str, base_uri: str | None = None) None#

Load the given content string with the specified base_uri.

If base_uri is not None, relative URLs in the content will be resolved against base_uri and absolute local paths must be children of the base_uri. For security reasons absolute local paths that are not children of base_uri will cause the web process to terminate. If you need to include URLs in content that are local paths in a different directory than base_uri you can build a data URI for them. When base_uri is None, it defaults to “about:blank”. The mime type of the document will be “text/html”. You can monitor the load operation by connecting to WebView::load-changed signal.

Parameters:
  • content – The HTML string to load

  • base_uri – The base URI for relative locations or None

load_plain_text(plain_text: str) None#

Load the specified plain_text string into web_view.

The mime type of document will be “text/plain”. You can monitor the load operation by connecting to WebView::load-changed signal.

Parameters:

plain_text – The plain text to load

load_request(request: URIRequest) None#

Requests loading of the specified URIRequest.

You can monitor the load operation by connecting to WebView::load-changed signal.

Parameters:

request – a URIRequest to load

load_uri(uri: str) None#

Requests loading of the specified URI string.

You can monitor the load operation by connecting to WebView::load-changed signal.

Parameters:

uri – an URI string

reload() None#

Reloads the current contents of web_view.

See also reload_bypass_cache().

reload_bypass_cache() None#

Reloads the current contents of web_view without using any cached data.

restore_session_state(state: WebViewSessionState) None#

Restore the web_view session state from state

Added in version 2.12.

Parameters:

state – a WebViewSessionState

save(save_mode: SaveMode, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Asynchronously save the current web page.

Asynchronously save the current web page associated to the WebView into a self-contained format using the mode specified in save_mode.

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

Parameters:
  • save_mode – the SaveMode specifying how the web page should be saved.

  • 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

save_finish(result: AsyncResult) InputStream#

Finish an asynchronous operation started with save().

Parameters:

result – a AsyncResult

save_to_file(file: File, save_mode: SaveMode, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Asynchronously save the current web page.

Asynchronously save the current web page associated to the WebView into a self-contained format using the mode specified in save_mode and writing it to file.

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

Parameters:
  • file – the File where the current web page should be saved to.

  • save_mode – the SaveMode specifying how the web page should be saved.

  • 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

save_to_file_finish(result: AsyncResult) bool#

Finish an asynchronous operation started with save_to_file().

Parameters:

result – a AsyncResult

send_message_to_page(message: UserMessage, cancellable: Cancellable | None = None, callback: Callable[[Object | None, AsyncResult, Any], None] | None = None, user_data: Any = None) None#

Send message to the WebKitWebPage corresponding to web_view.

If message is floating, it’s consumed. If you don’t expect any reply, or you simply want to ignore it, you can pass None as callback. When the operation is finished, callback will be called. You can then call send_message_to_page_finish() to get the message reply.

Added in version 2.28.

Parameters:
  • message – a UserMessage

  • cancellable – a Cancellable or None to ignore

  • callback – (nullable): A AsyncReadyCallback to call when the request is satisfied or None

  • user_data – the data to pass to callback function

send_message_to_page_finish(result: AsyncResult) UserMessage#

Finish an asynchronous operation started with send_message_to_page().

Added in version 2.28.

Parameters:

result – a AsyncResult

set_background_color(rgba: RGBA) None#

Sets the color that will be used to draw the web_view background.

Sets the color that will be used to draw the web_view background before the actual contents are rendered. Note that if the web page loaded in web_view specifies a background color, it will take precedence over the rgba color. By default the web_view background color is opaque white.

Added in version 2.8.

Parameters:

rgba – a RGBA

set_camera_capture_state(state: MediaCaptureState) None#

Set the camera capture state of a WebView.

If Settings:enable-mediastream is False, this method will have no visible effect. Once the state of the device has been set to NONE it cannot be changed anymore. The page can however request capture again using the mediaDevices API.

Added in version 2.34.

Parameters:

state – a MediaCaptureState

set_cors_allowlist(allowlist: list[str] | None = None) None#

Sets the allowlist for CORS.

Sets the allowlist for which Cross-Origin Resource Sharing checks are disabled in web_view. URI patterns must be of the form [protocol]://[host]/[path], each component may contain the wildcard character (*) to represent zero or more other characters. All three components are required and must not be omitted from the URI patterns.

Disabling CORS checks permits resources from other origins to load allowlisted resources. It does not permit the allowlisted resources to load resources from other origins.

If this function is called multiple times, only the allowlist set by the most recent call will be effective.

Added in version 2.34.

Parameters:

allowlist – an allowlist of URI patterns, or None

set_custom_charset(charset: str | None = None) None#

Sets the current custom character encoding override of web_view.

The custom character encoding will override any text encoding detected via HTTP headers or META tags. Calling this method will stop any current load operation and reload the current page. Setting the custom character encoding to None removes the character encoding override.

Parameters:

charset – a character encoding name or None

set_display_capture_state(state: MediaCaptureState) None#

Set the display capture state of a WebView.

If Settings:enable-mediastream is False, this method will have no visible effect. Once the state of the device has been set to NONE it cannot be changed anymore. The page can however request capture again using the mediaDevices API.

Added in version 2.34.

Parameters:

state – a MediaCaptureState

set_editable(editable: bool) None#

Sets whether the user is allowed to edit the HTML document.

If editable is True, web_view allows the user to edit the HTML document. If editable is False, an element in web_view's document can only be edited if the CONTENTEDITABLE attribute has been set on the element or one of its parent elements. By default a WebView is not editable.

Normally, a HTML document is not editable unless the elements within the document are editable. This function provides a way to make the contents of a WebView editable without altering the document or DOM structure.

Added in version 2.8.

Parameters:

editable – a gboolean indicating the editable state

set_input_method_context(context: InputMethodContext | None = None) None#

Set the InputMethodContext to be used by web_view.

Set the InputMethodContext to be used by web_view, or None to not use any input method. Note that the same InputMethodContext can’t be set on more than one WebView at the same time.

Added in version 2.28.

Parameters:

context – the InputMethodContext to set, or None

set_is_muted(muted: bool) None#

Sets the mute state of web_view.

Added in version 2.30.

Parameters:

muted – mute flag

set_microphone_capture_state(state: MediaCaptureState) None#

Set the microphone capture state of a WebView.

If Settings:enable-mediastream is False, this method will have no visible effect. Once the state of the device has been set to NONE it cannot be changed anymore. The page can however request capture again using the mediaDevices API.

Added in version 2.34.

Parameters:

state – a MediaCaptureState

set_settings(settings: Settings) None#

Sets the Settings to be applied to web_view.

The existing Settings of web_view will be replaced by settings. New settings are applied immediately on web_view. The same Settings object can be shared by multiple WebView<!– –>s.

Parameters:

settings – a Settings

set_zoom_level(zoom_level: float) None#

Set the zoom level of web_view.

Set the zoom level of web_view, i.e. the factor by which the view contents are scaled with respect to their original size.

Parameters:

zoom_level – the zoom level

stop_loading() None#

Stops any ongoing loading operation in web_view.

This method does nothing if no content is being loaded. If there is a loading operation in progress, it will be cancelled and WebView::load-failed signal will be emitted with CANCELLED error.

terminate_web_process() None#

Terminates the web process associated to web_view.

When the web process gets terminated using this method, the WebView::web-process-terminated signal is emitted with TERMINATED_BY_API as the reason for termination.

Added in version 2.34.

try_close() None#

Tries to close the web_view.

This will fire the onbeforeunload event to ask the user for confirmation to close the page. If there isn’t an onbeforeunload event handler or the user confirms to close the page, the WebView::close signal is emitted, otherwise nothing happens.

Added in version 2.12.

Properties#

class WebView
props.automation_presentation_type: AutomationBrowsingContextPresentation#

The type of the None singleton.

Added in version 2.28.

props.camera_capture_state: MediaCaptureState#

The type of the None singleton.

Added in version 2.34.

props.default_content_security_policy: str#

The type of the None singleton.

Added in version 2.38.

props.display_capture_state: MediaCaptureState#

The type of the None singleton.

Added in version 2.34.

props.editable: bool#

The type of the None singleton.

Added in version 2.8.

props.estimated_load_progress: float#

The type of the None singleton.

props.favicon: Texture#

The type of the None singleton.

props.is_controlled_by_automation: bool#

The type of the None singleton.

Added in version 2.18.

props.is_loading: bool#

The type of the None singleton.

props.is_muted: bool#

The type of the None singleton.

Added in version 2.30.

props.is_playing_audio: bool#

The type of the None singleton.

Added in version 2.8.

props.is_web_process_responsive: bool#

The type of the None singleton.

Added in version 2.34.

props.microphone_capture_state: MediaCaptureState#

The type of the None singleton.

Added in version 2.34.

props.network_session: NetworkSession#

The type of the None singleton.

Added in version 2.40.

props.page_id: int#

The type of the None singleton.

Added in version 2.28.

props.related_view: WebView#

The type of the None singleton.

Added in version 2.4.

props.settings: Settings#

The type of the None singleton.

Added in version 2.6.

props.title: str#

The type of the None singleton.

props.uri: str#

The type of the None singleton.

props.user_content_manager: UserContentManager#

The type of the None singleton.

Added in version 2.6.

props.web_context: WebContext#

The type of the None singleton.

props.web_extension_mode: WebExtensionMode#

The type of the None singleton.

Added in version 2.38.

props.website_policies: WebsitePolicies#

The type of the None singleton.

Added in version 2.30.

props.zoom_level: float#

The type of the None singleton.

Signals#

class WebView.signals
authenticate(request: AuthenticationRequest) bool#

The type of the None singleton.

Added in version 2.2.

Parameters:

request – a AuthenticationRequest

close() None#

The type of the None singleton.

context_menu(context_menu: ContextMenu, hit_test_result: HitTestResult) bool#

The type of the None singleton.

Parameters:
context_menu_dismissed() None#

The type of the None singleton.

create(navigation_action: NavigationAction) Widget#

The type of the None singleton.

Parameters:

navigation_action – a NavigationAction

decide_policy(decision: PolicyDecision, decision_type: PolicyDecisionType) bool#

The type of the None singleton.

Parameters:
enter_fullscreen() bool#

The type of the None singleton.

insecure_content_detected(event: InsecureContentEvent) None#

The type of the None singleton.

Deprecated since version 2.46: Please do not use it in newly written code

Parameters:

event – the InsecureContentEvent

leave_fullscreen() bool#

The type of the None singleton.

load_changed(load_event: LoadEvent) None#

The type of the None singleton.

Parameters:

load_event – the LoadEvent

load_failed(load_event: LoadEvent, failing_uri: str, error: GError) bool#

The type of the None singleton.

Parameters:
  • load_event – the LoadEvent of the load operation

  • failing_uri – the URI that failed to load

  • error – the Error that was triggered

load_failed_with_tls_errors(failing_uri: str, certificate: TlsCertificate, errors: TlsCertificateFlags) bool#

The type of the None singleton.

Added in version 2.6.

Parameters:
mouse_target_changed(hit_test_result: HitTestResult, modifiers: int) None#

The type of the None singleton.

Parameters:
permission_request(request: PermissionRequest) bool#

The type of the None singleton.

Parameters:

request – the PermissionRequest

print_(print_operation: PrintOperation) bool#

The type of the None singleton.

Parameters:

print_operation

query_permission_state(query: PermissionStateQuery) bool#

The type of the None singleton.

Added in version 2.40.

Parameters:

query – the PermissionStateQuery

ready_to_show() None#

The type of the None singleton.

resource_load_started(resource: WebResource, request: URIRequest) None#

The type of the None singleton.

Parameters:
run_as_modal() None#

The type of the None singleton.

run_color_chooser(request: ColorChooserRequest) bool#

The type of the None singleton.

Added in version 2.8.

Parameters:

request – a ColorChooserRequest

run_file_chooser(request: FileChooserRequest) bool#

The type of the None singleton.

Parameters:

request – a FileChooserRequest

script_dialog(dialog: ScriptDialog) bool#

The type of the None singleton.

Parameters:

dialog – the ScriptDialog to show

show_notification(notification: Notification) bool#

The type of the None singleton.

Added in version 2.8.

Parameters:

notification – a Notification

show_option_menu(menu: OptionMenu, rectangle: Rectangle) bool#

The type of the None singleton.

Added in version 2.18.

Parameters:
  • menu – the OptionMenu

  • rectangle – the option element area

submit_form(request: FormSubmissionRequest) None#

The type of the None singleton.

Parameters:

request – a FormSubmissionRequest

user_message_received(message: UserMessage) bool#

The type of the None singleton.

Added in version 2.28.

Parameters:

message – the UserMessage received

web_process_terminated(reason: WebProcessTerminationReason) None#

The type of the None singleton.

Added in version 2.20.

Parameters:

reason – the a WebProcessTerminationReason

Virtual Methods#

class WebView
do_authenticate(request: AuthenticationRequest) bool#

The type of the None singleton.

Parameters:

request

do_close() None#

The type of the None singleton.

do_context_menu(context_menu: ContextMenu, hit_test_result: HitTestResult) bool#

The type of the None singleton.

Parameters:
  • context_menu

  • hit_test_result

do_context_menu_dismissed() None#

The type of the None singleton.

do_decide_policy(decision: PolicyDecision, type: PolicyDecisionType) bool#

The type of the None singleton.

Parameters:
  • decision

  • type

do_enter_fullscreen() bool#

The type of the None singleton.

do_insecure_content_detected(event: InsecureContentEvent) None#

The type of the None singleton.

Parameters:

event

do_leave_fullscreen() bool#

The type of the None singleton.

do_load_changed(load_event: LoadEvent) None#

The type of the None singleton.

Parameters:

load_event

do_load_failed(load_event: LoadEvent, failing_uri: str, error: GError) bool#

The type of the None singleton.

Parameters:
  • load_event

  • failing_uri

  • error

do_load_failed_with_tls_errors(failing_uri: str, certificate: TlsCertificate, errors: TlsCertificateFlags) bool#

The type of the None singleton.

Parameters:
  • failing_uri

  • certificate

  • errors

do_mouse_target_changed(hit_test_result: HitTestResult, modifiers: int) None#

The type of the None singleton.

Parameters:
  • hit_test_result

  • modifiers

do_permission_request(permission_request: PermissionRequest) bool#

The type of the None singleton.

Parameters:

permission_request

do_print_(print_operation: PrintOperation) bool#

The type of the None singleton.

Parameters:

print_operation

do_query_permission_state(query: PermissionStateQuery) bool#

The type of the None singleton.

Parameters:

query

do_ready_to_show() None#

The type of the None singleton.

do_resource_load_started(resource: WebResource, request: URIRequest) None#

The type of the None singleton.

Parameters:
  • resource

  • request

do_run_as_modal() None#

The type of the None singleton.

do_run_color_chooser(request: ColorChooserRequest) bool#

The type of the None singleton.

Parameters:

request

do_run_file_chooser(request: FileChooserRequest) bool#

The type of the None singleton.

Parameters:

request

do_script_dialog(dialog: ScriptDialog) bool#

The type of the None singleton.

Parameters:

dialog

do_show_notification(notification: Notification) bool#

The type of the None singleton.

Parameters:

notification

do_show_option_menu(menu: OptionMenu, rectangle: Rectangle) bool#

The type of the None singleton.

Parameters:
  • menu

  • rectangle

do_submit_form(request: FormSubmissionRequest) None#

The type of the None singleton.

Parameters:

request

do_user_message_received(message: UserMessage) bool#

The type of the None singleton.

Parameters:

message

do_web_process_crashed() bool#

The type of the None singleton.

do_web_process_terminated(reason: WebProcessTerminationReason) None#

The type of the None singleton.

Parameters:

reason

Fields#

class WebView
parent_instance#
priv#