WebKit.WebView

g GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget WebKit.WebViewBase WebKit.WebViewBase Gtk.Widget->WebKit.WebViewBase WebKit.WebView WebKit.WebView WebKit.WebViewBase->WebKit.WebView

Subclasses:

None

Methods

Inherited:

Gtk.Widget (181), GObject.Object (37), Gtk.Accessible (15), Gtk.Buildable (1)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new ()

call_async_javascript_function (body, length, arguments, world_name, source_uri, cancellable, callback, *user_data)

call_async_javascript_function_finish (result)

can_execute_editing_command (command, cancellable, callback, *user_data)

can_execute_editing_command_finish (result)

can_go_back ()

can_go_forward ()

can_show_mime_type (mime_type)

download_uri (uri)

evaluate_javascript (script, length, world_name, source_uri, cancellable, callback, *user_data)

evaluate_javascript_finish (result)

execute_editing_command (command)

execute_editing_command_with_argument (command, argument)

get_automation_presentation_type ()

get_back_forward_list ()

get_background_color ()

get_camera_capture_state ()

get_context ()

get_custom_charset ()

get_default_content_security_policy ()

get_display_capture_state ()

get_editor_state ()

get_estimated_load_progress ()

get_favicon ()

get_find_controller ()

get_input_method_context ()

get_inspector ()

get_is_muted ()

get_is_web_process_responsive ()

get_main_resource ()

get_microphone_capture_state ()

get_network_session ()

get_page_id ()

get_session_state ()

get_settings ()

get_snapshot (region, options, cancellable, callback, *user_data)

get_snapshot_finish (result)

get_title ()

get_tls_info ()

get_uri ()

get_user_content_manager ()

get_web_extension_mode ()

get_website_policies ()

get_window_properties ()

get_zoom_level ()

go_back ()

go_forward ()

go_to_back_forward_list_item (list_item)

is_controlled_by_automation ()

is_editable ()

is_loading ()

is_playing_audio ()

load_alternate_html (content, content_uri, base_uri)

load_bytes (bytes, mime_type, encoding, base_uri)

load_html (content, base_uri)

load_plain_text (plain_text)

load_request (request)

load_uri (uri)

reload ()

reload_bypass_cache ()

restore_session_state (state)

save (save_mode, cancellable, callback, *user_data)

save_finish (result)

save_to_file (file, save_mode, cancellable, callback, *user_data)

save_to_file_finish (result)

send_message_to_page (message, cancellable, callback, *user_data)

send_message_to_page_finish (result)

set_background_color (rgba)

set_camera_capture_state (state)

set_cors_allowlist (allowlist)

set_custom_charset (charset)

set_display_capture_state (state)

set_editable (editable)

set_input_method_context (context)

set_is_muted (muted)

set_microphone_capture_state (state)

set_settings (settings)

set_zoom_level (zoom_level)

stop_loading ()

terminate_web_process ()

try_close ()

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)

do_authenticate (request)

do_close ()

do_context_menu (context_menu, hit_test_result)

do_context_menu_dismissed ()

do_decide_policy (decision, type)

do_enter_fullscreen ()

do_insecure_content_detected (event)

do_leave_fullscreen ()

do_load_changed (load_event)

do_load_failed (load_event, failing_uri, error)

do_load_failed_with_tls_errors (failing_uri, certificate, errors)

do_mouse_target_changed (hit_test_result, modifiers)

do_permission_request (permission_request)

do_print_ (print_operation)

do_query_permission_state (query)

do_ready_to_show ()

do_resource_load_started (resource, request)

do_run_as_modal ()

do_run_color_chooser (request)

do_run_file_chooser (request)

do_script_dialog (dialog)

do_show_notification (notification)

do_show_option_menu (menu, rectangle)

do_submit_form (request)

do_user_message_received (message)

do_web_process_crashed ()

do_web_process_terminated (reason)

Properties

Inherited:

Gtk.Widget (34), Gtk.Accessible (1)

Name

Type

Flags

Short Description

automation-presentation-type

WebKit.AutomationBrowsingContextPresentation

r/w/co

camera-capture-state

WebKit.MediaCaptureState

r/w

default-content-security-policy

str

r/w/co

display-capture-state

WebKit.MediaCaptureState

r/w

editable

bool

r/w

estimated-load-progress

float

r

favicon

Gdk.Texture

r

is-controlled-by-automation

bool

r/w/co

is-loading

bool

r

is-muted

bool

r/w

is-playing-audio

bool

r

is-web-process-responsive

bool

r

microphone-capture-state

WebKit.MediaCaptureState

r/w

network-session

WebKit.NetworkSession

r/w/co

page-id

int

r

related-view

WebKit.WebView

w/co

settings

WebKit.Settings

w/c

title

str

r

uri

str

r

user-content-manager

WebKit.UserContentManager

r/w/co

web-context

WebKit.WebContext

r/w/co

web-extension-mode

WebKit.WebExtensionMode

r/w/co

website-policies

WebKit.WebsitePolicies

r/w/co

zoom-level

float

r/w

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Name

Short Description

authenticate

This signal is emitted when the user is challenged with HTTP authentication.

close

Emitted when closing a WebKit.WebView is requested.

context-menu

Emitted when a context menu is about to be displayed to give the application a chance to customize the proposed menu, prevent the menu from being displayed, or build its own context menu.

context-menu-dismissed

Emitted after WebKit.WebView ::context-menu signal, if the context menu is shown, to notify that the context menu is dismissed.

create

Emitted when the creation of a new WebKit.WebView is requested.

decide-policy

This signal is emitted when WebKit is requesting the client to decide a policy decision, such as whether to navigate to a page, open a new window or whether or not to download a resource.

enter-fullscreen

Emitted when JavaScript code calls element.webkitRequestFullScreen.

insecure-content-detected

This signal is emitted when insecure content has been detected in a page loaded through a secure connection.

leave-fullscreen

Emitted when the WebKit.WebView is about to restore its top level window out of its full screen state.

load-changed

Emitted when a load operation in web_view changes.

load-failed

Emitted when an error occurs during a load operation.

load-failed-with-tls-errors

Emitted when a TLS error occurs during a load operation.

mouse-target-changed

This signal is emitted when the mouse cursor moves over an element such as a link, image or a media element.

permission-request

This signal is emitted when WebKit is requesting the client to decide about a permission request, such as allowing the browser to switch to fullscreen mode, sharing its location or similar operations.

print

Emitted when printing is requested on web_view, usually by a JavaScript call, before the print dialog is shown.

query-permission-state

This signal allows the User-Agent to respond to permission requests for powerful features, as specified by the Permissions W3C Specification.

ready-to-show

Emitted after WebKit.WebView ::create on the newly created WebKit.WebView when it should be displayed to the user.

resource-load-started

Emitted when a new resource is going to be loaded.

run-as-modal

Emitted after WebKit.WebView ::ready-to-show on the newly created WebKit.WebView when JavaScript code calls window.showModalDialog.

run-color-chooser

This signal is emitted when the user interacts with a HTML element, requesting from WebKit to show a dialog to select a color.

run-file-chooser

This signal is emitted when the user interacts with a HTML element, requesting from WebKit to show a dialog to select one or more files to be uploaded.

script-dialog

Emitted when JavaScript code calls window.alert, window.confirm or window.prompt, or when onbeforeunload event is fired.

show-notification

This signal is emitted when a notification should be presented to the user.

show-option-menu

This signal is emitted when a select element in web_view needs to display a dropdown menu.

submit-form

This signal is emitted when a form is about to be submitted.

user-message-received

This signal is emitted when a WebKit.UserMessage is received from the #WebKitWebPage corresponding to web_view.

web-process-terminated

This signal is emitted when the web process terminates abnormally due to reason.

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Name

Type

Access

Description

parent_instance

WebKit.WebViewBase

r

Class Details

class WebKit.WebView(**kwargs)
Bases:

WebKit.WebViewBase

Abstract:

No

Structure:

WebKit.WebViewClass

The central class of the WPE WebKit and WebKitGTK APIs.

WebKit.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 WebKit.WebView or a data string. With WebKit.Settings you can control various aspects of the rendering and loading of the content.

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

classmethod new()
Returns:

The newly created WebKit.WebView widget

Return type:

Gtk.Widget

Creates a new WebKit.WebView with the default WebKit.WebContext.

Creates a new WebKit.WebView with the default WebKit.WebContext and no WebKit.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().

call_async_javascript_function(body, length, arguments, world_name, source_uri, cancellable, callback, *user_data)
Parameters:

Asynchronously call body with arguments in the script world with name world_name of the main frame current context in self. The arguments values must be one of the following types, or contain only the following GLib.Variant 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 WebKit.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 WebKit.Settings :enable-javascript-markup.

When the operation is finished, callback will be called. You can then call WebKit.WebView.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:

```c static void web_view_javascript_finished (GObject.Object *object, Gio.AsyncResult *result, object user_data) { JavaScriptCore.Value *value; GLib.Error *error = None;

value = WebKit.WebView.call_async_javascript_function_finish (WEBKIT_WEB_VIEW (object), result, &error); if (!value) { g_warning (“Error running javascript: %s”, error->message); GLib.Error.free (error); return; }

if (JavaScriptCore.Value.is_number (value)) { gint32 int_value = JavaScriptCore.Value.to_string (value); JavaScriptCore.Exception *exception = JavaScriptCore.Context.get_exception (JavaScriptCore.Value.get_context (value)); if (exception) g_warning (“Error running javascript: %s”, JavaScriptCore.Exception.get_message (exception)); else g_print (“Script result: %d\n”, int_value); GLib.free (str_value); } else { g_warning (“Error running javascript: unexpected return value”); } GObject.Object.unref (value); }

static void web_view_evaluate_promise (WebKit.WebView *web_view) { GLib.VariantDict dict; g_variant_dict_init (&dict, None); g_variant_dict_insert (&dict, “count”, “u”, 42); GLib.Variant *args = GLib.VariantDict.end (&dict); const str *body = “return new Promise((resolve) => { resolve(count); });”; WebKit.WebView.call_async_javascript_function (web_view, body, -1, arguments, None, None, None, web_view_javascript_finished, None); } ```

New in version 2.40.

call_async_javascript_function_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a JavaScriptCore.Value with the return value of the async function or None in case of error

Return type:

JavaScriptCore.Value

Finish an asynchronous operation started with WebKit.WebView.call_async_javascript_function().

New in version 2.40.

can_execute_editing_command(command, cancellable, callback, *user_data)
Parameters:

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 WebKit.WebView.can_execute_editing_command_finish() to get the result of the operation.

can_execute_editing_command_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the editing command can be executed or False otherwise

Return type:

bool

Finish an asynchronous operation started with WebKit.WebView.can_execute_editing_command().

can_go_back()
Returns:

True if able to move back or False otherwise.

Return type:

bool

Determines whether self has a previous history item.

can_go_forward()
Returns:

True if able to move forward or False otherwise.

Return type:

bool

Determines whether self has a next history item.

can_show_mime_type(mime_type)
Parameters:

mime_type (str) – a MIME type

Returns:

True if the MIME type mime_type can be displayed or False otherwise

Return type:

bool

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

download_uri(uri)
Parameters:

uri (str) – the URI to download

Returns:

a new WebKit.Download representing the download operation.

Return type:

WebKit.Download

Requests downloading of the specified URI string for self.

evaluate_javascript(script, length, world_name, source_uri, cancellable, callback, *user_data)
Parameters:

Asynchronously evaluate script in the script world with name world_name of the main frame current context in self. 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 WebKit.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 WebKit.Settings :enable-javascript-markup.

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

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

```c static void web_view_javascript_finished (GObject.Object *object, Gio.AsyncResult *result, object user_data) { JavaScriptCore.Value *value; GLib.Error *error = None;

value = WebKit.WebView.evaluate_javascript_finish (WEBKIT_WEB_VIEW (object), result, &error); if (!value) { g_warning (“Error running javascript: %s”, error->message); GLib.Error.free (error); return; }

if (JavaScriptCore.Value.is_string (value)) { str *str_value = JavaScriptCore.Value.to_string (value); JavaScriptCore.Exception *exception = JavaScriptCore.Context.get_exception (JavaScriptCore.Value.get_context (value)); if (exception) g_warning (“Error running javascript: %s”, JavaScriptCore.Exception.get_message (exception)); else g_print (“Script result: %s\n”, str_value); GLib.free (str_value); } else { g_warning (“Error running javascript: unexpected return value”); } GObject.Object.unref (value); }

static void web_view_get_link_url (WebKit.WebView *web_view, const str *link_id) { str *script = g_strdup_printf (“window.document.getElementById(‘%s’).href;”, link_id); WebKit.WebView.evaluate_javascript (web_view, script, -1, None, None, None, web_view_javascript_finished, None); GLib.free (script); } ```

New in version 2.40.

evaluate_javascript_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a JavaScriptCore.Value with the result of the last executed statement in script or None in case of error

Return type:

JavaScriptCore.Value

Finish an asynchronous operation started with WebKit.WebView.evaluate_javascript().

New in version 2.40.

execute_editing_command(command)
Parameters:

command (str) – the command to execute

Request to execute the given command for self.

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

execute_editing_command_with_argument(command, argument)
Parameters:
  • command (str) – the command to execute

  • argument (str) – the command argument

Request to execute the given command with argument for self.

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

New in version 2.10.

get_automation_presentation_type()
Returns:

a WebKit.AutomationBrowsingContextPresentation.

Return type:

WebKit.AutomationBrowsingContextPresentation

Get the presentation type of WebKit.WebView when created for automation.

New in version 2.28.

get_back_forward_list()
Returns:

the WebKit.BackForwardList

Return type:

WebKit.BackForwardList

Obtains the WebKit.BackForwardList associated with the given WebKit.WebView.

The WebKit.BackForwardList is owned by the WebKit.WebView.

get_background_color()
Returns:

a Gdk.RGBA to fill in with the background color

Return type:

rgba: Gdk.RGBA

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

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

New in version 2.8.

get_camera_capture_state()
Returns:

The WebKit.MediaCaptureState of the camera device. If WebKit.Settings :enable-mediastream is False, this method will return WebKit.MediaCaptureState.NONE.

Return type:

WebKit.MediaCaptureState

Get the camera capture state of a WebKit.WebView.

New in version 2.34.

get_context()
Returns:

the WebKit.WebContext of the view

Return type:

WebKit.WebContext

Gets the web context of self.

get_custom_charset()
Returns:

the current custom character encoding name or None if no custom character encoding has been set.

Return type:

str

Returns the current custom character encoding name of self.

get_default_content_security_policy()
Returns:

The default policy or None

Return type:

str or None

Gets the configured default Content-Security-Policy.

New in version 2.38.

get_display_capture_state()
Returns:

The WebKit.MediaCaptureState of the display device. If WebKit.Settings :enable-mediastream is False, this method will return WebKit.MediaCaptureState.NONE.

Return type:

WebKit.MediaCaptureState

Get the display capture state of a WebKit.WebView.

New in version 2.34.

get_editor_state()
Returns:

the WebKit.EditorState of the view

Return type:

WebKit.EditorState

Gets the web editor state of self.

New in version 2.10.

get_estimated_load_progress()
Returns:

an estimate of the of the percent complete for a document load as a range from 0.0 to 1.0.

Return type:

float

Gets the value of the WebKit.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 self.

get_favicon()
Returns:

the favicon image or None if there’s no icon associated with self.

Return type:

Gdk.Texture

Returns favicon currently associated to self.

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

get_find_controller()
Returns:

the WebKit.FindController associated to this particular WebKit.WebView.

Return type:

WebKit.FindController

Gets the WebKit.FindController.

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

get_input_method_context()
Returns:

a WebKit.InputMethodContext, or None

Return type:

WebKit.InputMethodContext or None

Get the WebKit.InputMethodContext currently in use by self.

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

New in version 2.28.

get_inspector()
Returns:

the WebKit.WebInspector of self

Return type:

WebKit.WebInspector

Get the WebKit.WebInspector associated to self

get_is_muted()
Returns:

True if self audio is muted or False is audio is not muted.

Return type:

bool

Gets the mute state of self.

New in version 2.30.

get_is_web_process_responsive()
Returns:

True if the web process attached to self is responsive, or False otherwise.

Return type:

bool

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

New in version 2.34.

get_main_resource()
Returns:

the main WebKit.WebResource of the view or None if nothing has been loaded.

Return type:

WebKit.WebResource

Return the main resource of self.

get_microphone_capture_state()
Returns:

The WebKit.MediaCaptureState of the microphone device. If WebKit.Settings :enable-mediastream is False, this method will return WebKit.MediaCaptureState.NONE.

Return type:

WebKit.MediaCaptureState

Get the microphone capture state of a WebKit.WebView.

New in version 2.34.

get_network_session()
Returns:

a WebKit.NetworkSession

Return type:

WebKit.NetworkSession

Get the WebKit.NetworkSession associated to self.

New in version 2.40.

get_page_id()
Returns:

the page ID of self.

Return type:

int

Get the identifier of the #WebKitWebPage corresponding to the WebKit.WebView

get_session_state()
Returns:

a WebKit.WebViewSessionState

Return type:

WebKit.WebViewSessionState

Gets the current session state of self

New in version 2.12.

get_settings()
Returns:

the WebKit.Settings attached to self

Return type:

WebKit.Settings

Gets the WebKit.Settings currently applied to self.

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

get_snapshot(region, options, cancellable, callback, *user_data)
Parameters:

Asynchronously retrieves a snapshot of self for region.

options specifies how the snapshot should be rendered.

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

get_snapshot_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

an image with the retrieved snapshot, or None in case of error.

Return type:

Gdk.Texture

Finishes an asynchronous operation started with WebKit.WebView.get_snapshot().

get_title()
Returns:

The main frame document title of self.

Return type:

str

Gets the value of the WebKit.WebView :title property.

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

get_tls_info()
Returns:

True if the self connection uses HTTPS and a response has been received from the server, or False otherwise.

certificate:

return location for a Gio.TlsCertificate

errors:

return location for a Gio.TlsCertificateFlags the verification status of certificate

Return type:

(bool, certificate: Gio.TlsCertificate, errors: Gio.TlsCertificateFlags)

Retrieves the Gio.TlsCertificate associated with the main resource of self.

Retrieves the Gio.TlsCertificate associated with the main resource of self, and the Gio.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 WebKit.WebView ::load-changed and call this function when it’s emitted with WebKit.LoadEvent.COMMITTED event.

Note that this function provides no information about the security of the web page if the current WebKit.TLSErrorsPolicy is WebKit.TLSErrorsPolicy.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 WebKit.TLSErrorsPolicy is WebKit.TLSErrorsPolicy.FAIL, in which case subresources that fail certificate verification will be blocked.

get_uri()
Returns:

the current active URI of self or None if nothing has been loaded yet.

Return type:

str

Returns the current active URI of self.

The active URI might change during a load operation:

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

When a new load operation starts the active URI is the requested URI:

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

When the signal WebKit.WebView ::load-changed is emitted with WebKit.LoadEvent.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.

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

get_user_content_manager()
Returns:

the WebKit.UserContentManager associated with the view

Return type:

WebKit.UserContentManager

Gets the user content manager associated to self.

New in version 2.6.

get_web_extension_mode()
Returns:

the WebKit.WebExtensionMode

Return type:

WebKit.WebExtensionMode

Get the view’s WebKit.WebExtensionMode.

New in version 2.38.

get_website_policies()
Returns:

the default WebKit.WebsitePolicies associated with the view.

Return type:

WebKit.WebsitePolicies

Gets the default website policies.

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

See also WebKit.PolicyDecision.use_with_policies().

New in version 2.30.

get_window_properties()
Returns:

the WebKit.WindowProperties of self

Return type:

WebKit.WindowProperties

Get the WebKit.WindowProperties object.

Get the WebKit.WindowProperties object containing the properties that the window containing self should have.

get_zoom_level()
Returns:

the current zoom level of self

Return type:

float

Set the zoom level of self.

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

go_back()

Loads the previous history item.

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

go_forward()

Loads the next history item.

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

go_to_back_forward_list_item(list_item)
Parameters:

list_item (WebKit.BackForwardListItem) – a WebKit.BackForwardListItem

Loads the specific history item list_item.

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

is_controlled_by_automation()
Returns:

True if self is controlled by automation, or False otherwise.

Return type:

bool

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

Only WebKit.WebView s controlled by automation can be used in an automation session.

New in version 2.18.

is_editable()
Returns:

True if the user is allowed to edit the HTML document, or False otherwise.

Return type:

bool

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

When self 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 WebKit.WebView is not editable.

New in version 2.8.

is_loading()
Returns:

True if self is loading a page or False otherwise.

Return type:

bool

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

You can monitor when a WebKit.WebView is loading a page by connecting to notify::is-loading signal of self. 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()
Returns:

True if a page in self is playing audio or False otherwise.

Return type:

bool

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

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

New in version 2.8.

load_alternate_html(content, content_uri, base_uri)
Parameters:
  • content (str) – the new content to display as the main page of the self

  • content_uri (str) – the URI for the alternate page content

  • base_uri (str or None) – the base URI for relative locations or None

Load the given content string for the URI content_uri.

This allows clients to display page-loading errors in the WebKit.WebView itself. When this method is called from WebKit.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 WebKit.WebView.load_html().

load_bytes(bytes, mime_type, encoding, base_uri)
Parameters:
  • bytes (GLib.Bytes) – input data to load

  • mime_type (str or None) – the MIME type of bytes, or None

  • encoding (str or None) – the character encoding of bytes, or None

  • base_uri (str or None) – the base URI for relative locations or None

Load the specified bytes into self 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 WebKit.WebView ::load-changed signal.

New in version 2.6.

load_html(content, base_uri)
Parameters:
  • content (str) – The HTML string to load

  • base_uri (str or None) – The base URI for relative locations or 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 WebKit.WebView ::load-changed signal.

load_plain_text(plain_text)
Parameters:

plain_text (str) – The plain text to load

Load the specified plain_text string into self.

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

load_request(request)
Parameters:

request (WebKit.URIRequest) – a WebKit.URIRequest to load

Requests loading of the specified WebKit.URIRequest.

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

load_uri(uri)
Parameters:

uri (str) – an URI string

Requests loading of the specified URI string.

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

reload()

Reloads the current contents of self.

See also WebKit.WebView.reload_bypass_cache().

reload_bypass_cache()

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

restore_session_state(state)
Parameters:

state (WebKit.WebViewSessionState) – a WebKit.WebViewSessionState

Restore the self session state from state

New in version 2.12.

save(save_mode, cancellable, callback, *user_data)
Parameters:

Asynchronously save the current web page.

Asynchronously save the current web page associated to the WebKit.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 WebKit.WebView.save_finish() to get the result of the operation.

save_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a Gio.InputStream with the result of saving the current web page or None in case of error.

Return type:

Gio.InputStream

Finish an asynchronous operation started with WebKit.WebView.save().

save_to_file(file, save_mode, cancellable, callback, *user_data)
Parameters:

Asynchronously save the current web page.

Asynchronously save the current web page associated to the WebKit.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 WebKit.WebView.save_to_file_finish() to get the result of the operation.

save_to_file_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

True if the web page was successfully saved to a file or False otherwise.

Return type:

bool

Finish an asynchronous operation started with WebKit.WebView.save_to_file().

send_message_to_page(message, cancellable, callback, *user_data)
Parameters:

Send message to the #WebKitWebPage corresponding to self.

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 WebKit.WebView.send_message_to_page_finish() to get the message reply.

New in version 2.28.

send_message_to_page_finish(result)
Parameters:

result (Gio.AsyncResult) – a Gio.AsyncResult

Raises:

GLib.Error

Returns:

a WebKit.UserMessage with the reply or None in case of error.

Return type:

WebKit.UserMessage

Finish an asynchronous operation started with WebKit.WebView.send_message_to_page().

New in version 2.28.

set_background_color(rgba)
Parameters:

rgba (Gdk.RGBA) – a Gdk.RGBA

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

Sets the color that will be used to draw the self background before the actual contents are rendered. Note that if the web page loaded in self specifies a background color, it will take precedence over the rgba color. By default the self background color is opaque white. Note that the parent window must have a RGBA visual and Gtk.Widget :app-paintable property set to True for backgrounds colors to work.

```c static void browser_window_set_background_color (BrowserWindow *window, const Gdk.RGBA *rgba) { WebKit.WebView *web_view; GdkScreen *screen = gtk_window_get_screen (GTK_WINDOW (window)); GdkVisual *rgba_visual = gdk_screen_get_rgba_visual (screen);

if (!rgba_visual) return;

gtk_widget_set_visual (GTK_WIDGET (window), rgba_visual); gtk_widget_set_app_paintable (GTK_WIDGET (window), True);

web_view = browser_window_get_web_view (window); WebKit.WebView.set_background_color (web_view, rgba); } ```

New in version 2.8.

set_camera_capture_state(state)
Parameters:

state (WebKit.MediaCaptureState) – a WebKit.MediaCaptureState

Set the camera capture state of a WebKit.WebView.

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

New in version 2.34.

set_cors_allowlist(allowlist)
Parameters:

allowlist ([str] or None) – an allowlist of URI patterns, or None

Sets the allowlist for CORS.

Sets the allowlist for which Cross-Origin Resource Sharing checks are disabled in self. 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.

New in version 2.34.

set_custom_charset(charset)
Parameters:

charset (str or None) – a character encoding name or None

Sets the current custom character encoding override of self.

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.

set_display_capture_state(state)
Parameters:

state (WebKit.MediaCaptureState) – a WebKit.MediaCaptureState

Set the display capture state of a WebKit.WebView.

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

New in version 2.34.

set_editable(editable)
Parameters:

editable (bool) – a bool indicating the editable state

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

If editable is True, self allows the user to edit the HTML document. If editable is False, an element in self'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 WebKit.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 WebKit.WebView editable without altering the document or DOM structure.

New in version 2.8.

set_input_method_context(context)
Parameters:

context (WebKit.InputMethodContext or None) – the WebKit.InputMethodContext to set, or None

Set the WebKit.InputMethodContext to be used by self.

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

New in version 2.28.

set_is_muted(muted)
Parameters:

muted (bool) – mute flag

Sets the mute state of self.

New in version 2.30.

set_microphone_capture_state(state)
Parameters:

state (WebKit.MediaCaptureState) – a WebKit.MediaCaptureState

Set the microphone capture state of a WebKit.WebView.

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

New in version 2.34.

set_settings(settings)
Parameters:

settings (WebKit.Settings) – a WebKit.Settings

Sets the WebKit.Settings to be applied to self.

The existing WebKit.Settings of self will be replaced by settings. New settings are applied immediately on self. The same WebKit.Settings object can be shared by multiple WebKit.WebView s.

set_zoom_level(zoom_level)
Parameters:

zoom_level (float) – the zoom level

Set the zoom level of self.

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

stop_loading()

Stops any ongoing loading operation in self.

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

terminate_web_process()

Terminates the web process associated to self.

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

New in version 2.34.

try_close()

Tries to close the self.

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 WebKit.WebView ::close signal is emitted, otherwise nothing happens.

New in version 2.12.

do_authenticate(request) virtual
Parameters:

request (WebKit.AuthenticationRequest) –

Return type:

bool

do_close() virtual
do_context_menu(context_menu, hit_test_result) virtual
Parameters:
Return type:

bool

do_context_menu_dismissed() virtual
do_decide_policy(decision, type) virtual
Parameters:
Return type:

bool

do_enter_fullscreen() virtual
Return type:

bool

do_insecure_content_detected(event) virtual
Parameters:

event (WebKit.InsecureContentEvent) –

do_leave_fullscreen() virtual
Return type:

bool

do_load_changed(load_event) virtual
Parameters:

load_event (WebKit.LoadEvent) –

do_load_failed(load_event, failing_uri, error) virtual
Parameters:
Return type:

bool

do_load_failed_with_tls_errors(failing_uri, certificate, errors) virtual
Parameters:
Return type:

bool

do_mouse_target_changed(hit_test_result, modifiers) virtual
Parameters:
do_permission_request(permission_request) virtual
Parameters:

permission_request (WebKit.PermissionRequest) –

Return type:

bool

do_print_(print_operation) virtual
Parameters:

print_operation (WebKit.PrintOperation) –

Return type:

bool

do_query_permission_state(query) virtual
Parameters:

query (WebKit.PermissionStateQuery) –

Return type:

bool

do_ready_to_show() virtual
do_resource_load_started(resource, request) virtual
Parameters:
do_run_as_modal() virtual
do_run_color_chooser(request) virtual
Parameters:

request (WebKit.ColorChooserRequest) –

Return type:

bool

do_run_file_chooser(request) virtual
Parameters:

request (WebKit.FileChooserRequest) –

Return type:

bool

do_script_dialog(dialog) virtual
Parameters:

dialog (WebKit.ScriptDialog) –

Return type:

bool

do_show_notification(notification) virtual
Parameters:

notification (WebKit.Notification) –

Return type:

bool

do_show_option_menu(menu, rectangle) virtual
Parameters:
Return type:

bool

do_submit_form(request) virtual
Parameters:

request (WebKit.FormSubmissionRequest) –

do_user_message_received(message) virtual
Parameters:

message (WebKit.UserMessage) –

Return type:

bool

do_web_process_crashed() virtual
Return type:

bool

do_web_process_terminated(reason) virtual
Parameters:

reason (WebKit.WebProcessTerminationReason) –

Signal Details

WebKit.WebView.signals.authenticate(web_view, request)
Signal Name:

authenticate

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

This signal is emitted when the user is challenged with HTTP authentication. To let the application access or supply the credentials as well as to allow the client application to either cancel the request or perform the authentication, the signal will pass an instance of the WebKit.AuthenticationRequest in the request argument. To handle this signal asynchronously you should keep a ref of the request and return True. To disable HTTP authentication entirely, connect to this signal and simply return True.

The default signal handler will run a default authentication dialog asynchronously for the user to interact with.

New in version 2.2.

WebKit.WebView.signals.close(web_view)
Signal Name:

close

Flags:

RUN_LAST

Parameters:

web_view (WebKit.WebView) – The object which received the signal

Emitted when closing a WebKit.WebView is requested. This occurs when a call is made from JavaScript’s window.close function or after trying to close the web_view with WebKit.WebView.try_close(). It is the owner’s responsibility to handle this signal to hide or destroy the WebKit.WebView, if necessary.

WebKit.WebView.signals.context_menu(web_view, context_menu, hit_test_result)
Signal Name:

context-menu

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

Emitted when a context menu is about to be displayed to give the application a chance to customize the proposed menu, prevent the menu from being displayed, or build its own context menu.

If the signal handler returns False the context menu represented by context_menu will be shown, if it return True the context menu will not be shown.

The proposed WebKit.ContextMenu passed in context_menu argument is only valid during the signal emission.

WebKit.WebView.signals.context_menu_dismissed(web_view)
Signal Name:

context-menu-dismissed

Flags:

RUN_LAST

Parameters:

web_view (WebKit.WebView) – The object which received the signal

Emitted after WebKit.WebView ::context-menu signal, if the context menu is shown, to notify that the context menu is dismissed.

WebKit.WebView.signals.create(web_view, navigation_action)
Signal Name:

create

Flags:

RUN_LAST

Parameters:
Returns:

a newly allocated WebKit.WebView widget or None to propagate the event further.

Return type:

Gtk.Widget

Emitted when the creation of a new WebKit.WebView is requested. If this signal is handled the signal handler should return the newly created WebKit.WebView.

The WebKit.NavigationAction parameter contains information about the navigation action that triggered this signal.

The new WebKit.WebView must be related to web_view, see WebKit.WebView :related-view for more details.

The new WebKit.WebView should not be displayed to the user until the WebKit.WebView ::ready-to-show signal is emitted.

WebKit.WebView.signals.decide_policy(web_view, decision, decision_type)
Signal Name:

decide-policy

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

This signal is emitted when WebKit is requesting the client to decide a policy decision, such as whether to navigate to a page, open a new window or whether or not to download a resource. The WebKit.NavigationPolicyDecision passed in the decision argument is a generic type, but should be casted to a more specific type when making the decision. For example:

``c static gboolean decide_policy_cb (WebKitWebView *web_view,

WebKitPolicyDecision *decision, WebKitPolicyDecisionType type)

{

switch (type) { case WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION: {

WebKitNavigationPolicyDecision *navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision); // Make a policy decision here break;

} case WEBKIT_POLICY_DECISION_TYPE_NEW_WINDOW_ACTION: {

WebKitNavigationPolicyDecision *navigation_decision = WEBKIT_NAVIGATION_POLICY_DECISION (decision); // Make a policy decision here break;

} case WEBKIT_POLICY_DECISION_TYPE_RESPONSE:

WebKitResponsePolicyDecision *response = WEBKIT_RESPONSE_POLICY_DECISION (decision); // Make a policy decision here break;

default:

// Making no decision results in webkit_policy_decision_use() return FALSE;

} return TRUE;

}

It is possible to make policy decision asynchronously, by simply calling GObject.Object.ref() on the decision argument and returning True to block the default signal handler. If the last reference is removed on a WebKit.PolicyDecision and no decision has been made explicitly, WebKit.PolicyDecision.use() will be the default policy decision. The default signal handler will simply call WebKit.PolicyDecision.use(). Only the first policy decision chosen for a given WebKit.PolicyDecision will have any affect.

WebKit.WebView.signals.enter_fullscreen(web_view)
Signal Name:

enter-fullscreen

Flags:

RUN_LAST

Parameters:

web_view (WebKit.WebView) – The object which received the signal

Returns:

True to stop other handlers from being invoked for the event. False to continue emission of the event.

Return type:

bool

Emitted when JavaScript code calls element.webkitRequestFullScreen. If the signal is not handled the WebKit.WebView will proceed to full screen its top level window. This signal can be used by client code to request permission to the user prior doing the full screen transition and eventually prepare the top-level window (e.g. hide some widgets that would otherwise be part of the full screen window).

WebKit.WebView.signals.insecure_content_detected(web_view, event)
Signal Name:

insecure-content-detected

Flags:

RUN_LAST

Parameters:

This signal is emitted when insecure content has been detected in a page loaded through a secure connection. This typically means that a external resource from an unstrusted source has been run or displayed, resulting in a mix of HTTPS and non-HTTPS content.

You can check the event parameter to know exactly which kind of event has been detected (see WebKit.InsecureContentEvent).

WebKit.WebView.signals.leave_fullscreen(web_view)
Signal Name:

leave-fullscreen

Flags:

RUN_LAST

Parameters:

web_view (WebKit.WebView) – The object which received the signal

Returns:

True to stop other handlers from being invoked for the event. False to continue emission of the event.

Return type:

bool

Emitted when the WebKit.WebView is about to restore its top level window out of its full screen state. This signal can be used by client code to restore widgets hidden during the WebKit.WebView ::enter-fullscreen stage for instance.

WebKit.WebView.signals.load_changed(web_view, load_event)
Signal Name:

load-changed

Flags:

RUN_LAST

Parameters:

Emitted when a load operation in web_view changes. The signal is always emitted with WebKit.LoadEvent.STARTED when a new load request is made and WebKit.LoadEvent.FINISHED when the load finishes successfully or due to an error. When the ongoing load operation fails WebKit.WebView ::load-failed signal is emitted before WebKit.WebView ::load-changed is emitted with WebKit.LoadEvent.FINISHED. If a redirection is received from the server, this signal is emitted with WebKit.LoadEvent.REDIRECTED after the initial emission with WebKit.LoadEvent.STARTED and before WebKit.LoadEvent.COMMITTED. When the page content starts arriving the signal is emitted with WebKit.LoadEvent.COMMITTED event.

You can handle this signal and use a switch to track any ongoing load operation.

``c static void web_view_load_changed (WebKitWebView *web_view,

WebKitLoadEvent load_event, gpointer user_data)

{

switch (load_event) { case WEBKIT_LOAD_STARTED:

// New load, we have now a provisional URI provisional_uri = webkit_web_view_get_uri (web_view); // Here we could start a spinner or update the // location bar with the provisional URI break;

case WEBKIT_LOAD_REDIRECTED:

redirected_uri = webkit_web_view_get_uri (web_view); break;

case WEBKIT_LOAD_COMMITTED:

// The load is being performed. Current URI is // the final one and it won’t change unless a new // load is requested or a navigation within the // same page is performed uri = webkit_web_view_get_uri (web_view); break;

case WEBKIT_LOAD_FINISHED:

// Load finished, we can now stop the spinner break;

}

}

WebKit.WebView.signals.load_failed(web_view, load_event, failing_uri, error)
Signal Name:

load-failed

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

Emitted when an error occurs during a load operation. If the error happened when starting to load data for a page load_event will be WebKit.LoadEvent.STARTED. If it happened while loading a committed data source load_event will be WebKit.LoadEvent.COMMITTED. Since a load error causes the load operation to finish, the signal WebKit.WebView ::load-changed will always be emitted with WebKit.LoadEvent.FINISHED event right after this one.

By default, if the signal is not handled, a stock error page will be displayed. You need to handle the signal if you want to provide your own error page.

WebKit.WebView.signals.load_failed_with_tls_errors(web_view, failing_uri, certificate, errors)
Signal Name:

load-failed-with-tls-errors

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

Emitted when a TLS error occurs during a load operation. To allow an exception for this certificate and the host of failing_uri use webkit_web_context_allow_tls_certificate_for_host().

To handle this signal asynchronously you should call GObject.Object.ref() on certificate and return True.

If False is returned, WebKit.WebView ::load-failed will be emitted. The load will finish regardless of the returned value.

New in version 2.6.

WebKit.WebView.signals.mouse_target_changed(web_view, hit_test_result, modifiers)
Signal Name:

mouse-target-changed

Flags:

RUN_LAST

Parameters:

This signal is emitted when the mouse cursor moves over an element such as a link, image or a media element. To determine what type of element the mouse cursor is over, a Hit Test is performed on the current mouse coordinates and the result is passed in the hit_test_result argument. The modifiers argument is a bitmask of Gdk.ModifierType flags indicating the state of modifier keys. The signal is emitted again when the mouse is moved out of the current element with a new hit_test_result.

WebKit.WebView.signals.permission_request(web_view, request)
Signal Name:

permission-request

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

This signal is emitted when WebKit is requesting the client to decide about a permission request, such as allowing the browser to switch to fullscreen mode, sharing its location or similar operations.

A possible way to use this signal could be through a dialog allowing the user decide what to do with the request:

```c static bool permission_request_cb (WebKit.WebView *web_view, WebKit.PermissionRequest *request, Gtk.Window *parent_window) { Gtk.Widget *dialog = gtk_message_dialog_new (parent_window, Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, “Allow Permission Request?”); Gtk.Widget.show (dialog); int result = gtk_dialog_run (GTK_DIALOG (dialog));

switch (result) { case Gtk.ResponseType.YES: WebKit.PermissionRequest.allow (request); break; default: WebKit.PermissionRequest.deny (request); break; } gtk_widget_destroy (dialog);

return True; } ```

It is possible to handle permission requests asynchronously, by simply calling GObject.Object.ref() on the request argument and returning True to block the default signal handler. If the last reference is removed on a WebKit.PermissionRequest and the request has not been handled, WebKit.PermissionRequest.deny() will be the default action.

If the signal is not handled, the request will be completed automatically by the specific WebKit.PermissionRequest that could allow or deny it. Check the documentation of classes implementing WebKit.PermissionRequest interface to know their default action.

WebKit.WebView.signals.print_(web_view, print_operation)
Signal Name:

print

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

Emitted when printing is requested on web_view, usually by a JavaScript call, before the print dialog is shown. This signal can be used to set the initial print settings and page setup of print_operation to be used as default values in the print dialog. You can call WebKit.PrintOperation.set_print_settings() and WebKit.PrintOperation.set_page_setup() and then return False to propagate the event so that the print dialog is shown.

You can connect to this signal and return True to cancel the print operation or implement your own print dialog.

WebKit.WebView.signals.query_permission_state(web_view, query)
Signal Name:

query-permission-state

Flags:

RUN_LAST

Parameters:
Returns:

True if the message was handled, or False otherwise.

Return type:

bool

This signal allows the User-Agent to respond to permission requests for powerful features, as specified by the Permissions W3C Specification. You can reply to the query using WebKit.PermissionStateQuery.finish().

You can handle the query asynchronously by calling WebKit.PermissionStateQuery.ref() on query and returning True. If the last reference of query is removed and the query has not been handled, the query result will be set to %WEBKIT_QUERY_PERMISSION_PROMPT.

New in version 2.40.

WebKit.WebView.signals.ready_to_show(web_view)
Signal Name:

ready-to-show

Flags:

RUN_LAST

Parameters:

web_view (WebKit.WebView) – The object which received the signal

Emitted after WebKit.WebView ::create on the newly created WebKit.WebView when it should be displayed to the user. When this signal is emitted all the information about how the window should look, including size, position, whether the location, status and scrollbars should be displayed, is already set on the WebKit.WindowProperties of web_view. See also WebKit.WebView.get_window_properties().

WebKit.WebView.signals.resource_load_started(web_view, resource, request)
Signal Name:

resource-load-started

Flags:

RUN_LAST

Parameters:

Emitted when a new resource is going to be loaded. The request parameter contains the WebKit.URIRequest that will be sent to the server. You can monitor the load operation by connecting to the different signals of resource.

WebKit.WebView.signals.run_as_modal(web_view)
Signal Name:

run-as-modal

Flags:

RUN_LAST

Parameters:

web_view (WebKit.WebView) – The object which received the signal

Emitted after WebKit.WebView ::ready-to-show on the newly created WebKit.WebView when JavaScript code calls window.showModalDialog. The purpose of this signal is to allow the client application to prepare the new view to behave as modal. Once the signal is emitted a new main loop will be run to block user interaction in the parent WebKit.WebView until the new dialog is closed.

WebKit.WebView.signals.run_color_chooser(web_view, request)
Signal Name:

run-color-chooser

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

This signal is emitted when the user interacts with a HTML element, requesting from WebKit to show a dialog to select a color. To let the application know the details of the color chooser, as well as to allow the client application to either cancel the request or perform an actual color selection, the signal will pass an instance of the WebKit.ColorChooserRequest in the request argument.

It is possible to handle this request asynchronously by increasing the reference count of the request.

The default signal handler will asynchronously run a regular Gtk.ColorChooser for the user to interact with.

New in version 2.8.

WebKit.WebView.signals.run_file_chooser(web_view, request)
Signal Name:

run-file-chooser

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

This signal is emitted when the user interacts with a HTML element, requesting from WebKit to show a dialog to select one or more files to be uploaded. To let the application know the details of the file chooser, as well as to allow the client application to either cancel the request or perform an actual selection of files, the signal will pass an instance of the WebKit.FileChooserRequest in the request argument.

The default signal handler will asynchronously run a regular Gtk.FileChooserDialog for the user to interact with.

WebKit.WebView.signals.script_dialog(web_view, dialog)
Signal Name:

script-dialog

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

Emitted when JavaScript code calls window.alert, window.confirm or window.prompt, or when onbeforeunload event is fired. The dialog parameter should be used to build the dialog. If the signal is not handled a different dialog will be built and shown depending on the dialog type:

It is possible to handle the script dialog request asynchronously, by simply caling WebKit.ScriptDialog.ref() on the dialog argument and calling WebKit.ScriptDialog.close() when done. If the last reference is removed on a WebKit.ScriptDialog and the dialog has not been closed, WebKit.ScriptDialog.close() will be called.

WebKit.WebView.signals.show_notification(web_view, notification)
Signal Name:

show-notification

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked. False otherwise.

Return type:

bool

This signal is emitted when a notification should be presented to the user. The notification is kept alive until either: 1) the web page cancels it or 2) a navigation happens.

The default handler will emit a notification using libnotify, if built with support for it.

New in version 2.8.

WebKit.WebView.signals.show_option_menu(web_view, menu, rectangle)
Signal Name:

show-option-menu

Flags:

RUN_LAST

Parameters:
Returns:

True to stop other handlers from being invoked for the event. False to propagate the event further.

Return type:

bool

This signal is emitted when a select element in web_view needs to display a dropdown menu. This signal can be used to show a custom menu, using menu to get the details of all items that should be displayed. The area of the element in the WebKit.WebView is given as rectangle parameter, it can be used to position the menu. To handle this signal asynchronously you should keep a ref of the menu.

The default signal handler will pop up a #GtkMenu.

New in version 2.18.

WebKit.WebView.signals.submit_form(web_view, request)
Signal Name:

submit-form

Flags:

RUN_LAST

Parameters:

This signal is emitted when a form is about to be submitted. The request argument passed contains information about the text fields of the form. This is typically used to store login information that can be used later to pre-fill the form. The form will not be submitted until WebKit.FormSubmissionRequest.submit() is called.

It is possible to handle the form submission request asynchronously, by simply calling GObject.Object.ref() on the request argument and calling WebKit.FormSubmissionRequest.submit() when done to continue with the form submission. If the last reference is removed on a WebKit.FormSubmissionRequest and the form has not been submitted, WebKit.FormSubmissionRequest.submit() will be called.

WebKit.WebView.signals.user_message_received(web_view, message)
Signal Name:

user-message-received

Flags:

RUN_LAST

Parameters:
Returns:

True if the message was handled, or False otherwise.

Return type:

bool

This signal is emitted when a WebKit.UserMessage is received from the #WebKitWebPage corresponding to web_view. You can reply to the message using WebKit.UserMessage.send_reply().

You can handle the user message asynchronously by calling GObject.Object.ref() on message and returning True. If the last reference of message is removed and the message has not been replied to, the operation in the #WebKitWebPage will finish with error WebKit.UserMessageError.MESSAGE.

New in version 2.28.

WebKit.WebView.signals.web_process_terminated(web_view, reason)
Signal Name:

web-process-terminated

Flags:

RUN_LAST

Parameters:

This signal is emitted when the web process terminates abnormally due to reason.

New in version 2.20.

Property Details

WebKit.WebView.props.automation_presentation_type
Name:

automation-presentation-type

Type:

WebKit.AutomationBrowsingContextPresentation

Default Value:

WebKit.AutomationBrowsingContextPresentation.WINDOW

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The WebKit.AutomationBrowsingContextPresentation of WebKit.WebView. This should only be used when creating a new WebKit.WebView as a response to WebKit.AutomationSession ::create-web-view signal request. If the new WebView was added to a new tab of current browsing context window WebKit.AutomationBrowsingContextPresentation.TAB should be used.

New in version 2.28.

WebKit.WebView.props.camera_capture_state
Name:

camera-capture-state

Type:

WebKit.MediaCaptureState

Default Value:

WebKit.MediaCaptureState.NONE

Flags:

READABLE, WRITABLE

Capture state of the camera device. Whenever the user grants a media-request sent by the web page, requesting video capture capabilities (navigator.mediaDevices.getUserMedia({video: true})) this property will be set to WebKit.MediaCaptureState.ACTIVE.

The application can monitor this property and provide a visual indicator allowing to optionally deactivate or mute the capture device by setting this property respectively to WebKit.MediaCaptureState.NONE or WebKit.MediaCaptureState.MUTED.

If the capture state of the device is set to WebKit.MediaCaptureState.NONE the web-page can still re-request the permission to the user. Permission desision caching is left to the application.

New in version 2.34.

WebKit.WebView.props.default_content_security_policy
Name:

default-content-security-policy

Type:

str

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The default Content-Security-Policy used by the webview as if it were set by an HTTP header.

This applies to all content loaded including through navigation or via the various webkit_web_view_load_\* APIs. However do note that many WebKit APIs bypass Content-Security-Policy in general such as WebKit.UserContentManager and webkit_web_view_run_javascript().

Policies are additive so if a website sets its own policy it still applies on top of the policy set here.

New in version 2.38.

WebKit.WebView.props.display_capture_state
Name:

display-capture-state

Type:

WebKit.MediaCaptureState

Default Value:

WebKit.MediaCaptureState.NONE

Flags:

READABLE, WRITABLE

Capture state of the display device. Whenever the user grants a media-request sent by the web page, requesting screencasting capabilities (`navigator.mediaDevices.getDisplayMedia() this property will be set to WebKit.MediaCaptureState.ACTIVE.

The application can monitor this property and provide a visual indicator allowing to optionally deactivate or mute the capture device by setting this property respectively to WebKit.MediaCaptureState.NONE or WebKit.MediaCaptureState.MUTED.

If the capture state of the device is set to WebKit.MediaCaptureState.NONE the web-page can still re-request the permission to the user. Permission desision caching is left to the application.

New in version 2.34.

WebKit.WebView.props.editable
Name:

editable

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether the pages loaded inside WebKit.WebView are editable. For more information see WebKit.WebView.set_editable().

New in version 2.8.

WebKit.WebView.props.estimated_load_progress
Name:

estimated-load-progress

Type:

float

Default Value:

0.0

Flags:

READABLE

An estimate of the percent completion for the current loading operation. This value will range from 0.0 to 1.0 and, once a load completes, will remain at 1.0 until a new load starts, at which point it will be reset to 0.0. The value is an estimate based on the total number of bytes expected to be received for a document, including all its possible subresources and child documents.

WebKit.WebView.props.favicon
Name:

favicon

Type:

Gdk.Texture

Default Value:

None

Flags:

READABLE

The favicon currently associated to the WebKit.WebView. See WebKit.WebView.get_favicon() for more details.

WebKit.WebView.props.is_controlled_by_automation
Name:

is-controlled-by-automation

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

Whether the WebKit.WebView is controlled by automation. This should only be used when creating a new WebKit.WebView as a response to WebKit.AutomationSession ::create-web-view signal request.

New in version 2.18.

WebKit.WebView.props.is_loading
Name:

is-loading

Type:

bool

Default Value:

False

Flags:

READABLE

Whether the WebKit.WebView is currently loading a page. This property becomes True as soon as a new load operation is requested and before the WebKit.WebView ::load-changed signal is emitted with WebKit.LoadEvent.STARTED and at that point the active URI is the requested one. When the load operation finishes the property is set to False before WebKit.WebView ::load-changed is emitted with WebKit.LoadEvent.FINISHED.

WebKit.WebView.props.is_muted
Name:

is-muted

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Whether the WebKit.WebView audio is muted. When True, audio is silenced. It may still be playing, i.e. WebKit.WebView :is-playing-audio may be True.

New in version 2.30.

WebKit.WebView.props.is_playing_audio
Name:

is-playing-audio

Type:

bool

Default Value:

False

Flags:

READABLE

Whether the WebKit.WebView is currently playing audio from a page. This property becomes True as soon as web content starts playing any kind of audio. When a page is no longer playing any kind of sound, the property is set back to False.

New in version 2.8.

WebKit.WebView.props.is_web_process_responsive
Name:

is-web-process-responsive

Type:

bool

Default Value:

True

Flags:

READABLE

Whether the web process currently associated to the WebKit.WebView is responsive.

New in version 2.34.

WebKit.WebView.props.microphone_capture_state
Name:

microphone-capture-state

Type:

WebKit.MediaCaptureState

Default Value:

WebKit.MediaCaptureState.NONE

Flags:

READABLE, WRITABLE

Capture state of the microphone device. Whenever the user grants a media-request sent by the web page, requesting audio capture capabilities (navigator.mediaDevices.getUserMedia({audio: true})) this property will be set to WebKit.MediaCaptureState.ACTIVE.

The application can monitor this property and provide a visual indicator allowing to optionally deactivate or mute the capture device by setting this property respectively to WebKit.MediaCaptureState.NONE or WebKit.MediaCaptureState.MUTED.

If the capture state of the device is set to WebKit.MediaCaptureState.NONE the web-page can still re-request the permission to the user. Permission desision caching is left to the application.

New in version 2.34.

WebKit.WebView.props.network_session
Name:

network-session

Type:

WebKit.NetworkSession

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The WebKit.NetworkSession of the view

New in version 2.40.

WebKit.WebView.props.page_id
Name:

page-id

Type:

int

Default Value:

0

Flags:

READABLE

The identifier of the #WebKitWebPage corresponding to the WebKit.WebView.

New in version 2.28.

WebKit.WebView.props.related_view
Name:

related-view

Type:

WebKit.WebView

Default Value:

None

Flags:

WRITABLE, CONSTRUCT_ONLY

The related WebKit.WebView used when creating the view to share the same web process and network session. This property is not readable because the related web view is only valid during the object construction.

New in version 2.4.

WebKit.WebView.props.settings
Name:

settings

Type:

WebKit.Settings

Default Value:

None

Flags:

WRITABLE, CONSTRUCT

The WebKit.Settings of the view.

New in version 2.6.

WebKit.WebView.props.title
Name:

title

Type:

str

Default Value:

None

Flags:

READABLE

The main frame document title of this WebKit.WebView. If the title has not been received yet, it will be None.

WebKit.WebView.props.uri
Name:

uri

Type:

str

Default Value:

None

Flags:

READABLE

The current active URI of the WebKit.WebView. See WebKit.WebView.get_uri() for more details.

WebKit.WebView.props.user_content_manager
Name:

user-content-manager

Type:

WebKit.UserContentManager

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The WebKit.UserContentManager of the view.

New in version 2.6.

WebKit.WebView.props.web_context
Name:

web-context

Type:

WebKit.WebContext

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The WebKit.WebContext of the view.

WebKit.WebView.props.web_extension_mode
Name:

web-extension-mode

Type:

WebKit.WebExtensionMode

Default Value:

WebKit.WebExtensionMode.NONE

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

This configures web_view to treat the content as a WebExtension.

Note that this refers to the web standard WebExtensions and not WebKitWebExtensions.

In practice this limits the Content-Security-Policies that are allowed to be set. Some details can be found in Chrome’s documentation.

New in version 2.38.

WebKit.WebView.props.website_policies
Name:

website-policies

Type:

WebKit.WebsitePolicies

Default Value:

None

Flags:

READABLE, WRITABLE, CONSTRUCT_ONLY

The WebKit.WebsitePolicies for the view.

New in version 2.30.

WebKit.WebView.props.zoom_level
Name:

zoom-level

Type:

float

Default Value:

1.0

Flags:

READABLE, WRITABLE

The zoom level of the WebKit.WebView content. See WebKit.WebView.set_zoom_level() for more details.