Skip to content

WebView

WebView #

Bases: ConstrainedControl

Easily load webpages while allowing user interaction.

Note

Works only on the following platforms: iOS, Android, macOS and Web.

bgcolor: ft.OptionalColorValue = None class-attribute instance-attribute #

Defines the background color of the WebView.

enable_javascript: Optional[bool] = None class-attribute instance-attribute #

Enable or disable the JavaScript execution on the page.

Note that disabling the JavaScript execution on the page may result to unexpected web page behaviour.

on_console_message: ft.OptionalEventCallable[WebViewConsoleMessageEvent] = None class-attribute instance-attribute #

Fires when a log message is written to the JavaScript console.

Event handler argument is of type WebviewConsoleMessageEvent.

Note

Works only on the following platforms: iOS, Android and macOS.

on_javascript_alert_dialog: ft.OptionalEventCallable[WebViewJavaScriptEvent] = None class-attribute instance-attribute #

Fires when the web page attempts to display a JavaScript alert() dialog.

Event handler argument is of type WebviewJavaScriptEvent.

Note

Works only on the following platforms: iOS, Android and macOS.

on_page_ended: ft.OptionalControlEventCallable = None class-attribute instance-attribute #

Fires when all the webview page loading processes are ended.

Event handler argument's data property is of type str and contains the URL.

Note

Works only on the following platforms: iOS, Android and macOS.

on_page_started: ft.OptionalControlEventCallable = None class-attribute instance-attribute #

Fires soon as the first loading process of the webview page is started.

Event handler argument's data property is of type str and contains the URL.

Note

Works only on the following platforms: iOS, Android and macOS.

on_progress: ft.OptionalControlEventCallable = None class-attribute instance-attribute #

Fires when the progress of the webview page loading is changed.

Event handler argument's data property is of type int and contains the progress value.

Note

Works only on the following platforms: iOS, Android and macOS.

on_scroll: ft.OptionalEventCallable[WebViewScrollEvent] = None class-attribute instance-attribute #

Fires when the web page's scroll position changes.

Event handler argument is of type WebviewScrollEvent.

Note

Works only on the following platforms: iOS, Android and macOS.

on_url_change: ft.OptionalControlEventCallable = None class-attribute instance-attribute #

Fires when the URL of the webview page is changed.

Event handler argument's data property is of type str and contains the new URL.

Note

Works only on the following platforms: iOS, Android and macOS.

on_web_resource_error: ft.OptionalControlEventCallable = None class-attribute instance-attribute #

Fires when there is error with loading a webview page resource.

Event handler argument's data property is of type str and contains the error message.

Note

Works only on the following platforms: iOS, Android and macOS.

List of url-prefixes that should not be followed/loaded/downloaded.

url: str instance-attribute #

The URL of the web page to load.

can_go_back_async() -> bool async #

Whether there's a back history item.

Note

Works only on the following platforms: iOS, Android and macOS.

can_go_forward() -> bool async #

Whether there's a forward history item.

Note

Works only on the following platforms: iOS, Android and macOS.

clear_cache() #

Clears all caches used by the WebView.

The following caches are cleared
  • Browser HTTP Cache
  • Cache API caches. Service workers tend to use this cache.
  • Application cache
Note

Works only on the following platforms: iOS, Android and macOS.

clear_cache_async() async #

Clears all caches used by the WebView.

The following caches are cleared
  • Browser HTTP Cache
  • Cache API caches. Service workers tend to use this cache.
  • Application cache
Note

Works only on the following platforms: iOS, Android and macOS.

clear_local_storage() #

Clears the local storage used by the WebView.

Note

Works only on the following platforms: iOS, Android and macOS.

clear_local_storage_async() async #

Clears the local storage used by the WebView.

Note

Works only on the following platforms: iOS, Android and macOS.

disable_zoom() #

Disable zooming using the on-screen zoom controls and gestures.

Note

Works only on the following platforms: iOS, Android and macOS.

disable_zoom_async() async #

Disable zooming using the on-screen zoom controls and gestures.

Note

Works only on the following platforms: iOS, Android and macOS.

enable_zoom() #

Enable zooming using the on-screen zoom controls and gestures.

Note

Works only on the following platforms: iOS, Android and macOS.

enable_zoom_async() async #

Enable zooming using the on-screen zoom controls and gestures.

Note

Works only on the following platforms: iOS, Android and macOS.

get_current_url_async() -> Optional[str] async #

Returns the current URL that the WebView is displaying or None if no URL was ever loaded.

Note

Works only on the following platforms: iOS, Android and macOS.

get_title_async() -> Optional[str] async #

Returns the title of the currently loaded page.

Note

Works only on the following platforms: iOS, Android and macOS.

get_user_agent_async() -> Optional[str] async #

Returns the value used for the HTTP User-Agent: request header.

Note

Works only on the following platforms: iOS, Android and macOS.

go_back() #

Go back in the history of the webview, if can_go_back() is True.

Note

Works only on the following platforms: iOS, Android and macOS.

go_back_async() async #

Go back in the history of the webview, if can_go_back() is True.

Note

Works only on the following platforms: iOS, Android and macOS.

go_forward() #

Go forward in the history of the webview, if can_go_forward() is True.

Note

Works only on the following platforms: iOS, Android and macOS.

go_forward_async() async #

Go forward in the history of the webview, if can_go_forward() is True.

Note

Works only on the following platforms: iOS, Android and macOS.

load_file(absolute_path: str) #

Loads the provided local file.

Parameters:

Name Type Description Default
absolute_path str

The absolute path to the file.

required
Note

Works only on the following platforms: iOS, Android and macOS.

load_file_async(absolute_path: str) async #

Loads the provided local file.

Parameters:

Name Type Description Default
absolute_path str

The absolute path to the file.

required
Note

Works only on the following platforms: iOS, Android and macOS.

load_html(value: str, base_url: Optional[str] = None) #

Loads the provided HTML string.

Parameters:

Name Type Description Default
value str

The HTML string to load.

required
base_url str

The base URL to use when resolving relative URLs within the value.

None
Note

Works only on the following platforms: iOS, Android and macOS.

load_html_async(value: str, base_url: Optional[str] = None) async #

Loads the provided HTML string.

Parameters:

Name Type Description Default
value str

The HTML string to load.

required
base_url str

The base URL to use when resolving relative URLs within the value.

None
Note

Works only on the following platforms: iOS, Android and macOS.

load_request(url: str, method: RequestMethod = RequestMethod.GET) #

Makes an HTTP request and loads the response in the webview.

Parameters:

Name Type Description Default
url str

The URL to load.

required
method RequestMethod

The HTTP method to use. Defaults to RequestMethod.GET.

GET

load_request_async(url: str, method: RequestMethod = RequestMethod.GET) async #

Makes an HTTP request and loads the response in the webview.

Parameters:

Name Type Description Default
url str

The URL to load.

required
method RequestMethod

The HTTP method to use. Defaults to RequestMethod.GET.

GET
Note

Works only on the following platforms: iOS, Android and macOS.

reload() #

Reloads the current URL.

Note

Works only on the following platforms: iOS, Android and macOS.

reload_async() async #

Reloads the current URL.

Note

Works only on the following platforms: iOS, Android and macOS.

run_javascript(value: str) #

Runs the given JavaScript in the context of the current page.

Parameters:

Name Type Description Default
value str

The JavaScript code to run.

required
Note

Works only on the following platforms: iOS, Android and macOS.

run_javascript_async(value: str) async #

Runs the given JavaScript in the context of the current page.

Parameters:

Name Type Description Default
value str

The JavaScript code to run.

required
Note

Works only on the following platforms: iOS, Android and macOS.

scroll_by(x: int, y: int) #

Scroll by the provided number of webview pixels.

Parameters:

Name Type Description Default
x int

The number of pixels to scroll by on the x-axis.

required
y int

The number of pixels to scroll by on the y-axis.

required
Note

Works only on the following platforms: iOS, Android and macOS.

scroll_by_async(x: int, y: int) async #

Scroll by the provided number of webview pixels.

Parameters:

Name Type Description Default
x int

The number of pixels to scroll by on the x-axis.

required
y int

The number of pixels to scroll by on the y-axis.

required
Note

Works only on the following platforms: iOS, Android and macOS.

scroll_to(x: int, y: int) #

Scroll to the provided position of webview pixels.

Parameters:

Name Type Description Default
x int

The x-coordinate of the scroll position.

required
y int

The y-coordinate of the scroll position.

required
Note

Works only on the following platforms: iOS, Android and macOS.

scroll_to_async(x: int, y: int) async #

Scroll to the provided position of webview pixels.

Parameters:

Name Type Description Default
x int

The x-coordinate of the scroll position.

required
y int

The y-coordinate of the scroll position.

required
Note

Works only on the following platforms: iOS, Android and macOS.