@@ -9,13 +9,13 @@ stored in the WebView2 user data directory. This directory can be either
99configured by you during creation of the webview2 control or calculated
1010at runtime by the control if it wasn't set during creation.
1111
12- The current WebView2 code is designed to use a the directory that the hosting
13- application is running in as the default location. This has resulted in issues
12+ The current WebView2 code defaults the user data folder to the directory that
13+ contains the hosting application's executable. This has resulted in issues
1414if running from a folder for which the WebView2 process doesn't have write access
1515such as a Program Files folder. Work is in progress to change that default and
1616will be forthcoming in later changes.
1717
18- With the current guidance it is possible for you to have built
18+ With the current implementation it is possible for you to have built
1919logic into your application with an assumption where the User Data is
2020located. WebView2 changing that default can then result in a code error or
2121possible crash.
@@ -41,12 +41,18 @@ always be an absolute path.
4141``` cpp
4242HRESULT UserDataFolder ()
4343{
44- // get the current user data folder from the webview environment object
45- wil::unique_cotaskmem_string userDataFolder;
46- m_webViewEnvironment->get_UserDataFolder(&userDataFolder);
44+ Microsoft::WRL::ComPtr<ICoreWebView2Environment6> WebViewEnvironment6;
45+ m_webViewEnvironment->QueryInterface(IID_PPV_ARGS(&WebViewEnvironment6));
4746
48- // using the folder
49- WriteAppLog (userDataFolder.get(), "Logging information");
47+ if (WebViewEnvironment6 != NULLPTR)
48+ {
49+ // get the current user data folder from the webview environment object
50+ wil::unique_cotaskmem_string userDataFolder;
51+ WebViewEnvironment6->get_UserDataFolder(&userDataFolder);
52+
53+ // using the folder
54+ WriteAppLog (userDataFolder.get(), "Logging information");
55+ }
5056}```
5157
5258```c#
@@ -57,7 +63,7 @@ HRESULT UserDataFolder()
5763 if (e.IsSuccess)
5864 {
5965 // Get the current user data folder
60- String userDataFolder = webView.CoreWebView2.Environment-> UserDataFolder();
66+ String userDataFolder = webView.CoreWebView2.Environment. UserDataFolder();
6167
6268 // using the folder
6369 WriteAppLog(userDataFolder, "Logging information");
0 commit comments