Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Cache directory for WebView2

I am using WebView2 in WPF control to host the new edge.

In my code, I want to cache the cookie and browser specific data to a cache directory. The cache location should be set in the CoreWebView2EnvironmentOptions when creating the CoreWebView2Environment.

Is there any way we can achieve this ? Thanks in advance.

like image 301
DotNetSpartan Avatar asked Jun 19 '20 12:06

DotNetSpartan


People also ask

Where is WebView2 runtime installed?

As soon as WebView2 is available on the device, then your users can start using the Office features that rely on WebView2. After installation, you'll see an entry for Microsoft Edge WebView2 Runtime under Control Panel > Programs > Programs and Features.

How do I install WebView2 fixed?

To install WebView2 Runtime, go to the Microsoft web page Download the WebView2 Runtime (https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section). Under Evergreen Standalone Installer, click the x64 download button. Important: You must download the 64-bit version of the installer.

Do you need Microsoft edge WebView2 runtime?

WebView2 also doesn't require anything on your part as Microsoft is installing it automatically on Windows machines. It also doesn't require the Microsoft Edge browser to actually run. So, even if the browser isn't installed on your PC, let alone running, the Runtime process can and will run.


1 Answers

I have made a WPF application using WebView2 that sets the cache directory to user appdata folder. Below is a snippet of the code from my application.

var webView2Environment = await CoreWebView2Environment.CreateAsync(null, _cacheFolderPath);
await kioskBrowser.EnsureCoreWebView2Async(webView2Environment);

kioskBrowser.Source = new Uri(url);

You can find the rest of the code here KioskBrowser (GitHub)

like image 120
Morten Brudvik Avatar answered Oct 07 '22 18:10

Morten Brudvik