Struct dioxus_mobile::wry::webview::WebViewAttributes [−]
pub struct WebViewAttributes {
pub visible: bool,
pub transparent: bool,
pub url: Option<Url>,
pub html: Option<String>,
pub initialization_scripts: Vec<String, Global>,
pub custom_protocols: Vec<(String, Box<dyn Fn(&Request) + 'static, Global>), Global>,
pub rpc_handler: Option<Box<dyn Fn(&Window, RpcRequest) + 'static, Global>>,
pub file_drop_handler: Option<Box<dyn Fn(&Window, FileDropEvent) + 'static, Global>>,
}
Fields
visible: bool
Whether the WebView window should be visible.
transparent: bool
Whether the WebView should be transparent.
url: Option<Url>
Whether load the provided URL to WebView
.
html: Option<String>
Whether load the provided html string to WebView
.
This will be ignored if the url
is provided.
Warning
The loaded from html string will have different Origin on different platforms. And
servers which enforce CORS will need to add exact same Origin header in Access-Control-Allow-Origin
if you wish to send requests with native fetch
and XmlHttpRequest
APIs. Here are the
different Origin headers across platforms:
- macOS:
http://localhost
- Linux:
http://localhost
- Windows:
null
initialization_scripts: Vec<String, Global>
Initialize javascript code when loading new pages. When webview load a new page, this
initialization code will be executed. It is guaranteed that code is executed before
window.onload
.
custom_protocols: Vec<(String, Box<dyn Fn(&Request) + 'static, Global>), Global>
Register custom file loading protocols with pairs of scheme uri string and a handling closure.
The closure takes a url string slice, and returns a two item tuple of a vector of bytes which is the content and a mimetype string of the content.
Warning
Pages loaded from custom protocol will have different Origin on different platforms. And
servers which enforce CORS will need to add exact same Origin header in Access-Control-Allow-Origin
if you wish to send requests with native fetch
and XmlHttpRequest
APIs. Here are the
different Origin headers across platforms:
- macOS:
<scheme_name>://<path>
(so it will bewry://examples
incustom_protocol
example) - Linux: Though it’s same as macOS, there’s a bug that Origin header in the request will be
empty. So the only way to pass the server is setting
Access-Control-Allow-Origin: *
. - Windows:
https://<scheme_name>.<path>
(so it will behttps://wry.examples
incustom_protocol
example)
rpc_handler: Option<Box<dyn Fn(&Window, RpcRequest) + 'static, Global>>
Set the RPC handler to Communicate between the host Rust code and Javascript on webview.
The communication is done via JSON-RPC. Users can use this to register an incoming
request handler and reply with responses that are passed back to Javascript. On the Javascript
side the client is exposed via window.rpc
with two public methods:
- The
call()
function accepts a method name and parameters and expects a reply. - The
notify()
function accepts a method name and parameters but does not expect a reply.
Both functions return promises but notify()
resolves immediately.
file_drop_handler: Option<Box<dyn Fn(&Window, FileDropEvent) + 'static, Global>>
Set a handler closure to process incoming FileDropEvent
of the webview.
Blocking OS Default Behavior
Return true
in the callback to block the OS’ default behavior of handling a file drop.
Note, that if you do block this behavior, it won’t be possible to drop files on <input type="file">
forms.
Also note, that it’s not possible to manually set the value of a <input type="file">
via JavaScript for security reasons.
Trait Implementations
impl Default for WebViewAttributes
impl Default for WebViewAttributes
pub fn default() -> WebViewAttributes
pub fn default() -> WebViewAttributes
Returns the “default value” for a type. Read more