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
impl WebView
Sourcepub fn evaluate_script(&self, js: &str) -> Result<()>
pub fn evaluate_script(&self, js: &str) -> Result<()>
Evaluate and run javascript code.
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.
Exception is ignored because of the limitation on windows. You can catch it yourself and return as string as a workaround.
Get a list of cookies for specific url.
Sourcepub fn open_devtools(&self)
Available on debug-assertions enabled or crate feature devtools only.
pub fn open_devtools(&self)
devtools only.Open the web inspector which is usually called dev tool.
§Platform-specific
- Android / iOS: Not supported.
Sourcepub fn close_devtools(&self)
Available on debug-assertions enabled or crate feature devtools only.
pub fn close_devtools(&self)
devtools only.Close the web inspector which is usually called dev tool.
§Platform-specific
- Windows / Android / iOS: Not supported.
Sourcepub fn is_devtools_open(&self) -> bool
Available on debug-assertions enabled or crate feature devtools only.
pub fn is_devtools_open(&self) -> bool
devtools only.Gets the devtool window’s current visibility state.
§Platform-specific
- Windows / Android / iOS: Not supported.
Sourcepub fn zoom(&self, scale_factor: f64) -> Result<()>
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.
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.
§Platform-specific:
- macOS: Disables the default white WKWebView background via the
drawsBackgroundKVC key (same as thetransparentfeature) and setsunderPageBackgroundColor(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
0will be replaced by255
Sourcepub fn go_forward(&self) -> Result<()>
pub fn go_forward(&self) -> Result<()>
Go to the next page.
pub fn can_go_forward(&self) -> Result<bool>
pub fn can_go_back(&self) -> Result<bool>
Sourcepub fn load_url_with_headers(&self, url: &str, headers: HeaderMap) -> Result<()>
pub fn load_url_with_headers(&self, url: &str, headers: HeaderMap) -> Result<()>
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
pub fn bounds(&self) -> Result<Rect>
Sourcepub fn set_bounds(&self, bounds: Rect) -> Result<()>
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.
Sourcepub fn set_visible(&self, visible: bool) -> Result<()>
pub fn set_visible(&self, visible: bool) -> Result<()>
Shows or hides the webview.
Sourcepub fn focus_parent(&self) -> Result<()>
pub fn focus_parent(&self) -> Result<()>
Try moving focus away from the webview back to the parent window.
§Platform-specific:
- Android: Not implemented.