pub struct WebContext { /* private fields */ }Expand description
A context that is shared between multiple WebViews.
A browser would have a context for all the normal tabs and a different context for all the private/incognito tabs.
§Warning
If WebView is created by a WebContext. Dropping WebContext will cause WebView lose
some actions like custom protocol on Mac. Please keep both instances when you still wish to
interact with them.
Implementations§
Source§impl WebContext
impl WebContext
Sourcepub fn new(data_directory: Option<PathBuf>) -> Self
pub fn new(data_directory: Option<PathBuf>) -> Self
Create a new WebContext.
data_directory: Whether the WebView window should have a custom user data path. This is useful in Windows when a bundled application can’t have the webview data insideProgram Files.
§Platform-specific:
- Windows: Webview instances with different
CoreWebView2EnvironmentOptionsmust have differentdata_directorys 1
https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2environment.createcorewebview2controllerasync?view=webview2-dotnet-1.0.3719.77#:~:text=WebView%20creation%20fails%20if%20a%20running%20instance%20using%20the%20same%20user%20data%20folder%20exists%2C%20and%20the%20Environment%20objects%20have%20different%20CoreWebView2EnvironmentOptions. ↩
Sourcepub fn data_directory(&self) -> Option<&Path>
pub fn data_directory(&self) -> Option<&Path>
A reference to the data directory the context was created with.
Sourcepub fn is_custom_protocol_registered(&self, name: &str) -> bool
pub fn is_custom_protocol_registered(&self, name: &str) -> bool
Check if a custom protocol has been registered on this context.
Sourcepub fn set_allows_automation(&mut self, flag: bool)
pub fn set_allows_automation(&mut self, flag: bool)
Set if this context allows automation.
Note: This is currently only enforced on Linux, and has the stipulation that only 1 context allows automation at a time.