Skip to content

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

feat(owned-browser): inherit user's Arc cookies — agent webview ships logged-in

Louis Beaumont9b7c20323f5d
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
index 7982d4b82..14a1c11e7 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock
@@ -5461,7 +5461,6 @@ dependencies = [
"ed25519-dalek",
"hex",
"hmac",
- "num-bigint-dig",
"p256",
"p384",
"p521",
@@ -7034,7 +7033,6 @@ dependencies = [
"num-iter",
"num-traits",
"rand 0.8.5",
- "serde",
"smallvec 1.15.1",
"zeroize",
]
@@ -9446,7 +9444,6 @@ dependencies = [
"rand_core 0.10.0-rc-3",
"sha2 0.11.0-rc.5",
"signature 3.0.0-rc.6",
- "spki 0.8.0-rc.4",
"zeroize",
]
@@ -9516,13 +9513,11 @@ dependencies = [
"p521",
"pageant",
"pbkdf2",
- "pkcs1 0.8.0-rc.4",
"pkcs5",
"pkcs8 0.10.2",
"rand 0.9.2",
"rand_core 0.10.0-rc-3",
"ring",
- "rsa 0.10.0-rc.12",
"russh-cryptovec",
"russh-util",
"sec1",
@@ -9977,14 +9972,16 @@ dependencies = [
[[package]]
name = "screenpipe-app"
-version = "2.4.169"
+version = "2.4.170"
dependencies = [
+ "aes",
"anyhow",
"arboard",
"async-trait",
"axum 0.6.20",
"base64 0.22.1",
"block",
+ "cbc",
"cc",
"chrono",
"chrono-tz",
@@ -9999,6 +9996,7 @@ dependencies = [
"futures",
"futures-channel",
"gtk",
+ "hmac",
"hostname",
"http 0.2.12",
"icalendar",
@@ -10011,10 +10009,12 @@ dependencies = [
"objc",
"objc2 0.6.4",
"once_cell",
+ "pbkdf2",
"raw-window-handle",
"regex",
"reqwest 0.13.3",
"resvg",
+ "rusqlite",
"screenpipe-a11y",
"screenpipe-audio",
"screenpipe-config",
@@ -10027,9 +10027,11 @@ dependencies = [
"screenpipe-screen",
"screenpipe-secrets",
"screenpipe-vault",
+ "security-framework",
"sentry 0.42.0",
"serde",
"serde_json",
+ "sha1 0.10.6",
"sha2 0.10.9",
"specta",
"specta-typescript",
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
index a3272dd39..9d95561b7 100644
--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml
@@ -177,6 +177,19 @@ objc2 = { version = "0.6", features = ["relax-sign-encoding"] }
core-graphics-helmer-fork = "0.24.0"
nokhwa-bindings-macos = { git = "https://github.com/CapSoftware/nokhwa", rev = "0d3d1f30a78b" }
tauri-nspanel = { git = "https://github.com/ahkohd/tauri-nspanel", branch = "v2" }
+# Owned-browser cookie inheritance (see src/owned_browser_cookies.rs):
+# read Arc/Chrome's `Cookies` SQLite, pull the AES-128 key from the
+# macOS Keychain (`Arc Safe Storage`), AES-CBC decrypt each
+# `encrypted_value`, then inject via `WKHTTPCookieStore.setCookie` so
+# the agent's webview ships with the user's logged-in sessions instead
+# of an empty cookie jar.
+rusqlite = { version = "0.29.0", features = ["bundled"] }
+security-framework = "3.7.0"
+aes = "0.8.4"
+cbc = "0.1.2"
+hmac = "0.12.1"
+pbkdf2 = "0.12.2"
+sha1 = "0.10"
[target.'cfg(target_os = "windows")'.dependencies]
winreg = "0.52.0"
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index 1cd2fc0c2..56d441abe 100755
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -55,6 +55,8 @@ mod livetext;
mod livetext_ffi;
mod oauth;
mod owned_browser;
+#[cfg(target_os = "macos")]
+mod owned_browser_cookies;
mod permission_events;
mod permissions;
mod pi;
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs
index 5d619133b..2d6424173 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/owned_browser.rs
@@ -52,7 +52,7 @@ use tauri::{
WebviewWindowBuilder,
};
use tokio::sync::Mutex;
-use tracing::{info, warn};
+use tracing::{debug, info, warn};
use uuid::Uuid;
/// WebviewWindow label — also used by the frontend Tauri commands.
@@ -582,6 +582,21 @@ pub async fn owned_browser_navigate(app: AppHandle, url: String) -> Result<(), S
let parsed: url::Url = url
.parse()
.map_err(|e: url::ParseError| format!("invalid url: {e}"))?;
+
+ // Inherit the user's logged-in sessions from their real browser
+ // (currently Arc only) before navigating. Reads cookies for the
+ // target host out of the user's Cookies SQLite, AES-CBC-decrypts
+ // them with the macOS Keychain key, and pushes them into the
+ // shared `WKHTTPCookieStore`. Fails open: if Arc isn't installed,
+ // the Keychain prompt is denied, or decryption errors out, we
+ // navigate without injection — same behavior as before.
+ #[cfg(target_os = "macos")]
+ if let Some(host) = parsed.host_str() {
+ let cookies = crate::owned_browser_cookies::cookies_for_host(host).await;
+ if !cookies.is_empty() {
+ inject_cookies_macos(&app, &cookies).await;
+ }
+ }
let _ = app.emit(NAVIGATE_EVENT, parsed.as_str());
webview_window.navigate(parsed).map_err(|e| e.to_string())
}
@@ -595,3 +610,135 @@ pub async fn owned_browser_hide(app: AppHandle) -> Result<(), String> {
.ok_or_else(|| "owned-browser not initialized".to_string())?;
webview_window.hide().map_err(|e| e.to_string())
}
+
+/// 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)`
+/// call sends them on the request. WKHTTPCookieStore APIs are main-
+/// thread-only, so we hop the work over via `run_on_main_thread` and
+/// wait on a oneshot for completion. Fail-open: any objc / dictionary
+/// build error is logged and ignored — the navigate proceeds without
+/// the cookie that failed.
+#[cfg(target_os = "macos")]
+async fn inject_cookies_macos(app: &AppHandle, cookies: &[crate::owned_browser_cookies::Cookie]) {
+ use cocoa::base::{id, nil};
+ use cocoa::foundation::{NSArray, NSDictionary, NSString};
+ use objc::runtime::Object;
+ use objc::{class, msg_send, sel, sel_impl};
+
+ let cookies = cookies.to_vec();
+ let (tx, rx) = tokio::sync::oneshot::channel::<usize>();
+ let _ = app.run_on_main_thread(move || {
+ let mut injected: usize = 0;
+ unsafe {
+ let ds_class = class!(WKWebsiteDataStore);
+ let ds: id = msg_send![ds_class, defaultDataStore];
+ if ds.is_null() {
+ let _ = tx.send(0);
+ return;
+ }
+ let store: id = msg_send![ds, httpCookieStore];
+ if store.is_null() {
+ let _ = tx.send(0);
+ return;
+ }
+
+ for c in &cookies {
+ // Build NSDictionary of NSHTTPCookie properties. Keys
+ // are NSHTTPCookie* constants, but for simplicity we
+ // pass the documented string equivalents — Apple has
+ // kept these stable since 10.2 and the dictionary
+ // initializer accepts both.
+ let mut keys: Vec<id> = Vec::with_capacity(8);
+ let mut vals: Vec<id> = Vec::with_capacity(8);
+
+ let push = |k: &str, v: id, keys: &mut Vec<id>, vals: &mut Vec<id>| {
+ if v.is_null() {
+ return;
+ }
+ let key: id = NSString::alloc(nil).init_str(k);
+ keys.push(key);
+ vals.push(v);
+ };
+
+ let name_v: id = NSString::alloc(nil).init_str(&c.name);
+ push("Name", name_v, &mut keys, &mut vals);
+ let value_v: id = NSString::alloc(nil).init_str(&c.value);
+ push("Value", value_v, &mut keys, &mut vals);
+ // Domain must include the leading dot (or not) exactly
+ // as Chromium stored it — that's what controls scope.
+ let domain_v: id = NSString::alloc(nil).init_str(&c.domain);
+ push("Domain", domain_v, &mut keys, &mut vals);
+ let path_v: id = NSString::alloc(nil).init_str(
+ if c.path.is_empty() { "/" } else { &c.path },
+ );
+ push("Path", path_v, &mut keys, &mut vals);
+ if c.secure {
+ let s: id = NSString::alloc(nil).init_str("TRUE");
+ push("Secure", s, &mut keys, &mut vals);
+ }
+ // NSHTTPCookie's documented dictionary builder doesn't
+ // accept HttpOnly directly, but the literal key
+ // "HttpOnly" is forwarded through to the resulting
+ // cookie's flags by NSHTTPCookieStorage's parser.
+ if c.http_only {
+ let s: id = NSString::alloc(nil).init_str("TRUE");
+ push("HttpOnly", s, &mut keys, &mut vals);
+ }
+ if let Some(secs) = c.expires_at {
+ let date_class = class!(NSDate);
+ let date: id = msg_send![date_class, dateWithTimeIntervalSince1970: secs as f64];
+ push("Expires", date, &mut keys, &mut vals);
+ } else {
+ let s: id = NSString::alloc(nil).init_str("TRUE");
+ push("Discard", s, &mut keys, &mut vals);
+ }
+ // Chromium same_site mapping. -1 = unspecified, omit.
+ let same_site_str = match c.same_site {
+ 0 => Some("None"),
+ 1 => Some("Lax"),
+ 2 => Some("Strict"),
+ _ => None,
+ };
+ if let Some(ss) = same_site_str {
+ let v: id = NSString::alloc(nil).init_str(ss);
+ push("SameSite", v, &mut keys, &mut vals);
+ }
+ // NSHTTPCookieVersion = 0 → classic Netscape semantics.
+ let zero: id = NSString::alloc(nil).init_str("0");
+ push("Version", zero, &mut keys, &mut vals);
+
+ let keys_arr = NSArray::arrayWithObjects(nil, &keys);
+ let vals_arr = NSArray::arrayWithObjects(nil, &vals);
+ let dict: id = NSDictionary::dictionaryWithObjects_forKeys_(
+ nil, vals_arr, keys_arr,
+ );
+
+ let cookie_class = class!(NSHTTPCookie);
+ let ns_cookie: id =
+ msg_send![cookie_class, cookieWithProperties: dict];
+ if ns_cookie.is_null() {
+ continue;
+ }
+ // Fire-and-forget — completion fires async, but
+ // WKHTTPCookieStore commits to its in-memory map
+ // synchronously by the time setCookie returns.
+ let _: () = msg_send![store as *mut Object,
+ setCookie: ns_cookie
+ completionHandler: std::ptr::null_mut::<Object>()];
+ injected += 1;
+ }
+ }
+ let _ = tx.send(injected);
+ });
+
+ match rx.await {
+ Ok(n) => debug!(injected = n, "owned-browser: cookies pushed to WKHTTPCookieStore"),
+ Err(_) => warn!("owned-browser: cookie inject channel closed"),
+ }
+
+ // Tiny grace period so the WKHTTPCookieStore's own async commit to
+ // its on-disk store flushes before the upcoming navigate fires its
+ // request. Empirically <10ms; 50 covers slow startups.
+ tokio::time::sleep(std::time::Duration::from_millis(50)).await;
+}