webview2-user-data-relocation
Keep WebView2 profile/cache data out of installed payload directories
Files1
View on GitHubSKILL.md.squad/skills/webview2-user-data-relocation/SKILL.md
GitHubContext
Calling EnsureCoreWebView2Async() without an explicit environment lets WebView2 create App.exe.WebView2 beside the executable. That is fine for loose local runs, but it breaks MSI uninstall cleanliness because the install root is no longer immutable after first launch.
Pattern
Define a stable app-owned folder under %LOCALAPPDATA%, then bootstrap WebView2 with an explicit environment:
Directory.CreateDirectory(userDataFolder);
var environment = await CoreWebView2Environment.CreateAsync(userDataFolder: userDataFolder);
await webView.EnsureCoreWebView2Async(environment);
PanelNester Convention
- Put desktop mutable state behind
DesktopStoragePaths. - Current WebView2 profile path:
%LOCALAPPDATA%\PanelNester\WebView2\UserData - Keep MSI payload under
%LOCALAPPDATA%\Programs\PanelNesterstrictly for installed binaries and bundled web assets.
When To Apply
- Per-user MSI installs
- Any installer that must uninstall back to a clean install root
- Any desktop host where browser cache/profile data must stay separate from shipped files
Validation Checklist
- Install the MSI as a standard user.
- Launch once and wait long enough for WebView2 initialization.
- Confirm no
*.exe.WebView2folder appears beside the installed EXE. - Confirm the explicit
%LOCALAPPDATA%\AppName\...profile folder exists. - Uninstall and verify the install root is removed cleanly.