WebView2 초기화 시 UserDataFolder를 temp로 지정

This commit is contained in:
2026-07-01 15:00:40 +09:00
parent f290500eff
commit 2bf3abe591
@@ -1,4 +1,5 @@
using Microsoft.Web.WebView2.Core; using Microsoft.Web.WebView2.Core;
using System.IO;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Threading; using System.Windows.Threading;
@@ -29,7 +30,7 @@ namespace BaronSoftware.SSO
{ {
try try
{ {
await webview.EnsureCoreWebView2Async(); await webview.EnsureCoreWebView2Async(await CreateWebView2EnvironmentAsync());
webview.CoreWebView2.NavigationStarting += OnNavigationStarting; webview.CoreWebView2.NavigationStarting += OnNavigationStarting;
webview.CoreWebView2.Navigate(_authorizeUrl); webview.CoreWebView2.Navigate(_authorizeUrl);
} }
@@ -95,7 +96,7 @@ namespace BaronSoftware.SSO
holder.Show(); // WebView2 초기화에 필요한 HWND 확보(화면 밖) holder.Show(); // WebView2 초기화에 필요한 HWND 확보(화면 밖)
try try
{ {
await web.EnsureCoreWebView2Async(); await web.EnsureCoreWebView2Async(await CreateWebView2EnvironmentAsync());
// DeleteAllCookies()는 즉시 반환이라, 디스크 반영 전에 Dispose되면 쿠키가 남아 // DeleteAllCookies()는 즉시 반환이라, 디스크 반영 전에 Dispose되면 쿠키가 남아
// 다음 로그인이 SSO로 조용히 통과될 수 있다. 완료까지 await하는 ClearBrowsingDataAsync로 // 다음 로그인이 SSO로 조용히 통과될 수 있다. 완료까지 await하는 ClearBrowsingDataAsync로
// SSO 세션 쿠키/사이트 데이터를 확실히 제거한다. // SSO 세션 쿠키/사이트 데이터를 확실히 제거한다.
@@ -148,7 +149,7 @@ namespace BaronSoftware.SSO
try try
{ {
await web.EnsureCoreWebView2Async(); await web.EnsureCoreWebView2Async(await CreateWebView2EnvironmentAsync());
web.CoreWebView2.NavigationStarting += OnNavStarting; web.CoreWebView2.NavigationStarting += OnNavStarting;
web.CoreWebView2.Navigate(endSessionUrl); web.CoreWebView2.Navigate(endSessionUrl);
@@ -166,6 +167,12 @@ namespace BaronSoftware.SSO
} }
}); });
private static Task<CoreWebView2Environment> CreateWebView2EnvironmentAsync()
{
var userDataFolder = Path.Combine(Path.GetTempPath(), "BaronSSO", "WebView2");
return CoreWebView2Environment.CreateAsync(userDataFolder: userDataFolder);
}
/// <summary> /// <summary>
/// 호출 스레드(MTA/STA)와 무관하게, 전용 STA 스레드에서 자체 Dispatcher 메시지펌프를 돌려 /// 호출 스레드(MTA/STA)와 무관하게, 전용 STA 스레드에서 자체 Dispatcher 메시지펌프를 돌려
/// WPF/WebView2 UI 작업을 실행하고 그 결과를 Task로 반환한다. /// WPF/WebView2 UI 작업을 실행하고 그 결과를 Task로 반환한다.