Fixed the check of the session cookie on macOS

This commit is contained in:
Thorsten Sommer committed 2026-10-31 20:23:47 +01:00
1 parent f06d2f553b
commit 9c9ca6e3a8
1 file changed
+21 -1
+21 -1
View File
@@ -50,7 +50,7 @@ pub fn hand_over_session_cookie(window: &WebviewWindow, app_url: &Url) {
return;
}
match window.cookies_for_url(app_url.clone()) {
match app_host_cookies(window, app_url) {
Ok(cookies) if cookies.iter().any(|cookie| cookie.name() == SESSION_COOKIE_NAME) => {
info!(Source = "App access"; "The app window got its session cookie.");
},
@@ -65,6 +65,26 @@ pub fn hand_over_session_cookie(window: &WebviewWindow, app_url: &Url) {
}
}
/// Reads the cookies of the app host from the given window.
///
/// On macOS, wry picks the cookies for a URL by comparing their domain with the domain of the
/// URL. An IP address such as the app host has no domain in that sense, so wry would never find
/// a cookie of the app there. We read all cookies instead and pick those of the app host
/// ourselves.
#[cfg(target_os = "macos")]
fn app_host_cookies(window: &WebviewWindow, _app_url: &Url) -> tauri::Result<Vec<Cookie<'static>>> {
Ok(window.cookies()?.into_iter().filter(|cookie| cookie.domain() == Some(APP_HOST)).collect())
}
/// Reads the cookies of the app host from the given window.
///
/// WebView2 and WebKitGTK pick the cookies for a URL by themselves. Reading all cookies instead
/// would need WebKitGTK 2.42 or newer.
#[cfg(not(target_os = "macos"))]
fn app_host_cookies(window: &WebviewWindow, app_url: &Url) -> tauri::Result<Vec<Cookie<'static>>> {
window.cookies_for_url(app_url.clone())
}
/// Returns the link with which another browser gets the session cookie of a development build,
/// such as the browser of an agent which checks a change in the running app.
#[cfg(debug_assertions)]