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
impl WebView
sourcepub fn new(window: Window) -> Result<Self>
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.
sourcepub fn evaluate_script(&self, js: &str) -> Result<()>
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.
sourcepub fn evaluate_script_with_callback(
&self,
js: &str,
callback: impl Fn(String) + Send + 'static
) -> Result<()>
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.
sourcepub fn open_devtools(&self)
pub fn open_devtools(&self)
Open the web inspector which is usually called dev tool.
Platform-specific
- Android / iOS: Not supported.
sourcepub fn close_devtools(&self)
pub fn close_devtools(&self)
Close the web inspector which is usually called dev tool.
Platform-specific
- Windows / Android / iOS: Not supported.
sourcepub fn is_devtools_open(&self) -> bool
pub fn is_devtools_open(&self) -> bool
Gets the devtool window’s current visibility state.
Platform-specific
- Windows / Android / iOS: Not supported.
sourcepub fn inner_size(&self) -> PhysicalSize<u32>
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());
sourcepub fn zoom(&self, scale_factor: f64)
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.
sourcepub fn set_background_color(&self, background_color: RGBA) -> Result<()>
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 by255
sourcepub fn load_url_with_headers(&self, url: &str, headers: HeaderMap)
pub fn load_url_with_headers(&self, url: &str, headers: HeaderMap)
Navigate to the specified url using the specified headers
sourcepub fn clear_all_browsing_data(&self) -> Result<()>
pub fn clear_all_browsing_data(&self) -> Result<()>
Clear all browsing data