YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(owned-browser): cookie injection ran on the wrong navigate path — agent saw empty jar
Louis Beaumont7d68c54deb1c
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rsindex b71afed1a..9106e2c5e 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs@@ -150,6 +150,7 @@ impl OwnedWebviewHandle for TauriOwnedHandle {let parsed: url::Url = target.parse().map_err(|e: url::ParseError| format!("invalid url: {e}"))?;+ inject_cookies_for_url(&self.app, &parsed).await;let _ = self.app.emit(NAVIGATE_EVENT, parsed.as_str());webview_window.navigate(parsed)@@ -285,6 +286,16 @@ impl OwnedWebviewHandle for TauriOwnedHandle {let _ = webview_window.show();}+ // Push the user's real-browser cookies for this host into+ // WKHTTPCookieStore before issuing the navigate, so the request+ // ships logged-in. This is the agent's primary path+ // (POST /connections/browsers/owned-default/eval — see the+ // OwnedBrowser trait impl in screenpipe-connect); without this+ // hook the agent always lands on the logged-out version of the+ // site even though the Tauri-command-driven sidebar restore+ // path was injecting correctly.+ inject_cookies_for_url(&self.app, &parsed).await;+let _ = self.app.emit(NAVIGATE_EVENT, parsed.as_str());webview_window.navigate(parsed)@@ -583,23 +594,8 @@ pub async fn owned_browser_navigate(app: AppHandle, url: String) -> Result<(), S.parse().map_err(|e: url::ParseError| format!("invalid url: {e}"))?;- // Inherit the user's logged-in sessions from their real browser.- // `cookies_for_host` is cross-platform but currently only returns- // non-empty on macOS (Arc / Chrome / Brave / Edge). The injection- // step is platform-gated because each webview engine has its own- // cookie-store API: macOS WKHTTPCookieStore today; Windows WebView2- // ICoreWebView2CookieManager and Linux webkit2gtk to come.- // Fail-open everywhere — any error and we navigate without cookies,- // same UX as before this hook existed.- if let Some(host) = parsed.host_str() {- let cookies = crate::owned_browser_cookies::cookies_for_host(host).await;- if !cookies.is_empty() {- #[cfg(target_os = "macos")]- inject_cookies_macos(&app, &cookies).await;- #[cfg(not(target_os = "macos"))]- let _ = (&app, &cookies); // suppress unused warning until inject impls land- }- }+ // Inherit the user's logged-in sessions before navigating.+ inject_cookies_for_url(&app, &parsed).await;let _ = app.emit(NAVIGATE_EVENT, parsed.as_str());webview_window.navigate(parsed).map_err(|e| e.to_string())}@@ -614,6 +610,38 @@ pub async fn owned_browser_hide(app: AppHandle) -> Result<(), String> {webview_window.hide().map_err(|e| e.to_string())}+/// Cross-platform cookie pre-navigate hook. Resolves the URL's host,+/// reads cookies from every supported real browser via+/// `owned_browser_cookies::cookies_for_host`, and dispatches them to+/// the platform's webview cookie-store API. Called from every path+/// that issues `webview.navigate(...)` against the owned browser:+/// - the `owned_browser_navigate` Tauri command (frontend sidebar+/// restoring per-conversation state),+/// - `TauriOwnedHandle::navigate` (agent's fire-and-forget native+/// navigate via the connect HTTP API),+/// - `TauriOwnedHandle::eval` when a target URL is supplied (agent's+/// eval-with-navigate path).+/// Fail-open everywhere — any error and we proceed to navigate+/// without injection.+async fn inject_cookies_for_url(app: &AppHandle, url: &url::Url) {+ let Some(host) = url.host_str() else {+ return;+ };+ let cookies = crate::owned_browser_cookies::cookies_for_host(host).await;+ if cookies.is_empty() {+ return;+ }+ info!(+ host,+ count = cookies.len(),+ "owned-browser: injecting cookies before navigate"+ );+ #[cfg(target_os = "macos")]+ inject_cookies_macos(app, &cookies).await;+ #[cfg(not(target_os = "macos"))]+ let _ = (app, &cookies); // until Windows/Linux injectors land+}+/// macOS only: push a batch of cookies (read from the user's real/// browser by [`crate::owned_browser_cookies::cookies_for_host`]) into/// the shared `WKHTTPCookieStore` so the next `webview.navigate(url)`diff --git a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser_cookies.rs b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser_cookies.rsindex e1f75fb4f..6ccb40980 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser_cookies.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser_cookies.rs@@ -76,7 +76,7 @@ use std::sync::OnceLock;#[cfg(target_os = "macos")]use tokio::sync::Mutex;-use tracing::{debug, warn};+use tracing::{debug, info, warn};#[cfg(target_os = "macos")]use aes::cipher::{block_padding::Pkcs7, BlockDecryptMut, KeyIvInit};@@ -172,7 +172,7 @@ async fn cookies_for_host_impl(host: &str) -> Vec<Cookie> {match read_cookies(source, &host_owned) {Ok(mut c) => {if !c.is_empty() {- debug!(+ info!(source = source.name,count = c.len(),"owned-browser cookies: read"