Struct wry::webview::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 during event handling to it. WebView also contains the associate Window with it.

Implementations§

source§

impl WebView

source

pub fn new(window: Window) -> Result<Self>

Create a WebView from provided Window. Note that calling this directly loses abilities to initialize scripts, add ipc handler, and many more before starting WebView. To benefit from above features, create a WebViewBuilder instead.

Platform-specific behavior:

  • Unix: This method must be called in a gtk thread. Usually this means it should be called in the same thread with the EventLoop you create.
source

pub fn window(&self) -> &Window

Get the Window associate with the WebView. This can let you perform window related actions.

source

pub fn url(&self) -> Url

Get the current url of the webview

source

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

Evaluate and run javascript code. Must be called on the same thread who created the WebView. Use EventLoopProxy and a custom event to send scripts from other threads.

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. Must be called on the same thread who created the WebView. Use EventLoopProxy and a custom event to send scripts from other threads.

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

  • ** Android:** Not implemented yet.
source

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

Launch print modal for the webview content.

source

pub fn open_devtools(&self)

Open the web inspector which is usually called dev tool.

Platform-specific
  • Android / iOS: Not supported.
source

pub fn close_devtools(&self)

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

Gets the devtool window’s current visibility state.

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

pub fn inner_size(&self) -> PhysicalSize<u32>

Gets the physical size of the webview’s client area. This is a drop-in replacement for Window::inner_size because on some platforms (currently, only macOS), it will return an incorrect size.

use wry::{
  application::{
    event_loop::EventLoop,
    window::WindowBuilder
  },
  webview::WebViewBuilder,
};
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let webview = WebViewBuilder::new(window)
  .unwrap()
  .build()
  .unwrap();

// This returns incorrect window size on macOS.
println!("{:?}", webview.window().inner_size());
// Instead, this always returns the correct window size.
println!("{:?}", webview.inner_size());
source

pub fn zoom(&self, scale_factor: f64)

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.

Platfrom-specific:
  • macOS / iOS: Not implemented.
  • 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)

Navigate to the specified url

source

pub fn load_url_with_headers(&self, url: &str, headers: HeaderMap)

Navigate to the specified url using the specified headers

source

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

Clear all browsing data

Trait Implementations§

source§

impl Drop for WebView

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl WebviewExtUnix for WebView

source§

fn webview(&self) -> Rc<WebView>

Returns Webkit2gtk Webview handle

Auto Trait Implementations§

§

impl !RefUnwindSafe for WebView

§

impl !Send for WebView

§

impl !Sync for WebView

§

impl Unpin for WebView

§

impl !UnwindSafe for WebView

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more