Skip to main content

WebView

Struct WebView 

Source
pub struct WebView { /* private fields */ }
Expand description

The fundamental type to present a WebView.

WebViewBuilder / WebView are the basic building blocks to construct WebView contents and scripts for those who prefer to control fine grained window creation and event handling. WebView presents the actual WebView window and let you still able to perform actions on it.

Implementations§

Source§

impl WebView

Source

pub fn id(&self) -> WebViewId<'_>

Returns the id of this webview.

Source

pub fn url(&self) -> Result<String>

Get the current url of the webview

Source

pub fn evaluate_script(&self, js: &str) -> Result<()>

Evaluate and run javascript code.

Source

pub fn evaluate_script_with_callback( &self, js: &str, callback: impl Fn(String) + Send + 'static, ) -> Result<()>

Evaluate and run javascript code with callback function. The evaluation result will be serialized into a JSON string and passed to the callback function.

Exception is ignored because of the limitation on windows. You can catch it yourself and return as string as a workaround.

Source

pub fn print(&self) -> Result<()>

Launch print modal for the webview content.

Source

pub fn cookies_for_url(&self, url: &str) -> Result<Vec<Cookie<'static>>>

Get a list of cookies for specific url.

Source

pub fn cookies(&self) -> Result<Vec<Cookie<'static>>>

Get the list of cookies.

§Platform-specific
  • Android: Unsupported, always returns an empty Vec.

Set a cookie for the webview.

§Platform-specific
  • Android: Not supported.

Delete a cookie for the webview.

§Platform-specific
  • Android: Not supported.
Source

pub fn open_devtools(&self)

Available on debug-assertions enabled or crate feature devtools only.

Open the web inspector which is usually called dev tool.

§Platform-specific
  • Android / iOS: Not supported.
Source

pub fn close_devtools(&self)

Available on debug-assertions enabled or crate feature devtools only.

Close the web inspector which is usually called dev tool.

§Platform-specific
  • Windows / Android / iOS: Not supported.
Source

pub fn is_devtools_open(&self) -> bool

Available on debug-assertions enabled or crate feature devtools only.

Gets the devtool window’s current visibility state.

§Platform-specific
  • Windows / Android / iOS: Not supported.
Source

pub fn zoom(&self, scale_factor: f64) -> Result<()>

Set the webview zoom level

§Platform-specific:
  • Android: Not supported.
  • macOS: available on macOS 11+ only.
  • iOS: available on iOS 14+ only.
Source

pub fn set_background_color(&self, background_color: RGBA) -> Result<()>

Specify the webview background color.

The color uses the RGBA format.

§Platform-specific:
  • macOS: Disables the default white WKWebView background via the drawsBackground KVC key (same as the transparent feature) and sets underPageBackgroundColor (macOS 12+) for overscroll areas.
  • Windows:
    • On Windows 7, transparency is not supported and the alpha value will be ignored.
    • On Windows higher than 7: translucent colors are not supported so any alpha value other than 0 will be replaced by 255
Source

pub fn load_url(&self, url: &str) -> Result<()>

Navigate to the specified url

Source

pub fn reload(&self) -> Result<()>

Reloads the current page.

Source

pub fn go_forward(&self) -> Result<()>

Go to the next page.

Source

pub fn go_back(&self) -> Result<()>

Go to the previous page.

Source

pub fn can_go_forward(&self) -> Result<bool>

Source

pub fn can_go_back(&self) -> Result<bool>

Source

pub fn load_url_with_headers(&self, url: &str, headers: HeaderMap) -> Result<()>

Navigate to the specified url using the specified headers

Source

pub fn load_html(&self, html: &str) -> Result<()>

Load html content into the webview

Source

pub fn clear_all_browsing_data(&self) -> Result<()>

Clear all browsing data

Source

pub fn bounds(&self) -> Result<Rect>

Source

pub fn set_bounds(&self, bounds: Rect) -> Result<()>

Set the webview bounds.

This is only effective if the webview was created as a child or created using WebViewBuilderExtUnix::build_gtk with gtk::Fixed.

Source

pub fn set_visible(&self, visible: bool) -> Result<()>

Shows or hides the webview.

Source

pub fn focus(&self) -> Result<()>

Try moving focus to the webview.

Source

pub fn focus_parent(&self) -> Result<()>

Try moving focus away from the webview back to the parent window.

§Platform-specific:
  • Android: Not implemented.

Trait Implementations§

Source§

impl WebViewExtUnix for WebView

Available on gtk only.
Source§

fn new_gtk<W>(widget: &W) -> Result<Self>
where W: IsA<Container>,

Create the webview inside a GTK container widget, such as GTK window. Read more
Source§

fn webview(&self) -> WebView

Returns Webkit2gtk Webview handle
Source§

fn reparent<W>(&self, widget: &W) -> Result<()>
where W: IsA<Container>,

Attaches this webview to the given Widget and removes it from the current one.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.