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

fix: detect Arc browser incognito windows via tab URL/title matching

Louis Beaumont4e72ac14733a
diff --git a/crates/screenpipe-a11y/src/incognito/macos.rs b/crates/screenpipe-a11y/src/incognito/macos.rs
index ce1840516..495617725 100644
--- a/crates/screenpipe-a11y/src/incognito/macos.rs
+++ b/crates/screenpipe-a11y/src/incognito/macos.rs
@@ -9,6 +9,10 @@
//! match by title, since the captured window may not be the front window.
//! This is **locale-independent** and reliable for those browsers.
//!
+//! For Arc specifically, we also collect tab URLs and titles from incognito
+//! windows because Arc's accessibility tree reports the Space name (e.g.
+//! "Space 1") instead of the page title, causing title-only matching to fail.
+//!
//! For non-Chromium browsers (Firefox, Safari) we fall back to title-based
//! detection via [`super::titles::is_title_private`].
@@ -57,15 +61,34 @@ fn applescript_app_name(app_name: &str) -> &str {
}
}
-/// Batch cache: stores the set of incognito window titles for a browser app.
-/// One AppleScript call fetches ALL incognito titles, so switching between
-/// windows within the TTL is free (no extra osascript spawns).
+/// Batch cache: stores incognito window titles, tab titles, and tab URLs.
+/// One AppleScript call fetches everything, so switching between windows
+/// within the TTL is free (no extra osascript spawns).
struct BatchCache {
app_name: String,
- incognito_titles: HashSet<String>,
+ /// Window titles of incognito windows (from AppleScript `name of w`)
+ incognito_window_titles: HashSet<String>,
+ /// Tab titles inside incognito windows (for Arc where window title != tab title)
+ incognito_tab_titles: HashSet<String>,
+ /// Tab URLs inside incognito windows (most reliable for Arc matching)
+ incognito_tab_urls: HashSet<String>,
timestamp: Instant,
}
+impl BatchCache {
+ fn is_incognito(&self, window_title: &str) -> bool {
+ self.incognito_window_titles.contains(window_title)
+ || self.incognito_tab_titles.contains(window_title)
+ }
+
+ fn has_incognito_url(&self, url: &str) -> bool {
+ if url.is_empty() {
+ return false;
+ }
+ self.incognito_tab_urls.contains(url)
+ }
+}
+
pub struct MacOSIncognitoDetector {
cache: Mutex<Option<BatchCache>>,
}
@@ -84,19 +107,27 @@ impl MacOSIncognitoDetector {
CHROMIUM_BROWSERS.iter().any(|b| lower.contains(b))
}
- /// Batch-query all incognito window titles for a browser via AppleScript.
+ fn is_arc(app_name: &str) -> bool {
+ app_name.to_lowercase() == "arc"
+ }
+
+ /// Batch-query all incognito window titles (+ tab info for Arc) via AppleScript.
///
- /// Returns `Some(set_of_incognito_titles)` (possibly empty), or `None`
- /// if the script failed (browser not running, permission denied, etc.).
+ /// Returns `Some(BatchCache data)` or `None` if the script failed.
///
- /// Cost: one `osascript` spawn (~150-200 ms), regardless of window count.
- fn query_all_incognito_titles(app_name: &str) -> Option<HashSet<String>> {
+ /// For Arc, the script also collects tab URLs and titles from incognito
+ /// windows because Arc's accessibility tree uses Space names instead of
+ /// page titles for the window name.
+ fn query_incognito_data(app_name: &str) -> Option<(HashSet<String>, HashSet<String>, HashSet<String>)> {
let as_name = applescript_app_name(app_name);
-
- // Collects names of all incognito windows, separated by "|||".
- // Checks both `mode` (Chrome/Edge/Brave) and `incognito` property (Arc).
- let script = format!(
- r#"if application "{name}" is running then
+ let is_arc = Self::is_arc(app_name);
+
+ // For Arc: collect window names, tab titles, and tab URLs from incognito windows.
+ // For other Chromium browsers: just collect window names (they match the a11y title).
+ // Format: "WINDOW:title|||TAB:tab_title|||URL:tab_url" separated by "~~~"
+ let script = if is_arc {
+ format!(
+ r#"if application "{name}" is running then
tell application "{name}"
set result_list to ""
repeat with w in every window
@@ -110,10 +141,20 @@ impl MacOSIncognitoDetector {
end try
end if
if dominated then
+ set wname to name of w
+ set entry to "WINDOW:" & wname
+ repeat with t in every tab of w
+ try
+ set entry to entry & "|||TAB:" & (title of t)
+ end try
+ try
+ set entry to entry & "|||URL:" & (URL of t)
+ end try
+ end repeat
if result_list is "" then
- set result_list to name of w
+ set result_list to entry
else
- set result_list to result_list & "|||" & name of w
+ set result_list to result_list & "~~~" & entry
end if
end if
end repeat
@@ -123,8 +164,40 @@ impl MacOSIncognitoDetector {
else
return "not_running"
end if"#,
- name = as_name,
- );
+ name = as_name,
+ )
+ } else {
+ format!(
+ r#"if application "{name}" is running then
+ tell application "{name}"
+ set result_list to ""
+ repeat with w in every window
+ set dominated to false
+ try
+ if mode of w is "incognito" then set dominated to true
+ end try
+ if not dominated then
+ try
+ if incognito of w then set dominated to true
+ end try
+ end if
+ if dominated then
+ if result_list is "" then
+ set result_list to "WINDOW:" & name of w
+ else
+ set result_list to result_list & "~~~" & "WINDOW:" & name of w
+ end if
+ end if
+ end repeat
+ if result_list is "" then return "none"
+ return result_list
+ end tell
+else
+ return "not_running"
+end if"#,
+ name = as_name,
+ )
+ };
let output = match Command::new("osascript").arg("-e").arg(&script).output() {
Ok(o) => o,
@@ -154,26 +227,43 @@ end if"#,
}
"none" => {
debug!("incognito: {} has no incognito windows", as_name);
- Some(HashSet::new())
+ Some((HashSet::new(), HashSet::new(), HashSet::new()))
}
_ => {
- let titles: HashSet<String> = result.split("|||").map(|s| s.to_string()).collect();
+ let mut window_titles = HashSet::new();
+ let mut tab_titles = HashSet::new();
+ let mut tab_urls = HashSet::new();
+
+ for window_entry in result.split("~~~") {
+ for part in window_entry.split("|||") {
+ if let Some(title) = part.strip_prefix("WINDOW:") {
+ window_titles.insert(title.to_string());
+ } else if let Some(title) = part.strip_prefix("TAB:") {
+ tab_titles.insert(title.to_string());
+ } else if let Some(url) = part.strip_prefix("URL:") {
+ tab_urls.insert(url.to_string());
+ }
+ }
+ }
+
debug!(
- "incognito: {} has {} incognito window(s): {:?}",
+ "incognito: {} has {} incognito window(s), {} tab title(s), {} url(s)",
as_name,
- titles.len(),
- titles
+ window_titles.len(),
+ tab_titles.len(),
+ tab_urls.len(),
);
- Some(titles)
+ debug!("incognito: window_titles={:?}", window_titles);
+ debug!("incognito: tab_titles={:?}", tab_titles);
+ debug!("incognito: tab_urls={:?}", tab_urls);
+
+ Some((window_titles, tab_titles, tab_urls))
}
}
}
/// Check if a window title belongs to an incognito window, using the
/// batch cache. One AppleScript call per browser per TTL interval.
- ///
- /// The lock is released before calling AppleScript (~150-200 ms) to
- /// avoid blocking concurrent threads.
fn check_with_cache(&self, app_name: &str, window_title: &str) -> Option<bool> {
// Check cache while holding the lock briefly.
{
@@ -182,33 +272,52 @@ end if"#,
if entry.app_name.eq_ignore_ascii_case(app_name)
&& entry.timestamp.elapsed() < CACHE_TTL
{
- return Some(entry.incognito_titles.contains(window_title));
+ return Some(entry.is_incognito(window_title));
}
}
}
// Lock released — safe to do slow I/O.
- let titles = Self::query_all_incognito_titles(app_name)?;
- let is_incognito = titles.contains(window_title);
+ let (window_titles, tab_titles, tab_urls) = Self::query_incognito_data(app_name)?;
+ let is_incognito = window_titles.contains(window_title)
+ || tab_titles.contains(window_title);
// Re-acquire lock to store the result.
{
let mut cache = self.cache.lock().unwrap_or_else(|e| e.into_inner());
*cache = Some(BatchCache {
app_name: app_name.to_string(),
- incognito_titles: titles,
+ incognito_window_titles: window_titles,
+ incognito_tab_titles: tab_titles,
+ incognito_tab_urls: tab_urls,
timestamp: Instant::now(),
});
}
Some(is_incognito)
}
+
+ /// Check if a URL belongs to an incognito tab (used as fallback when
+ /// window title matching fails, especially for Arc).
+ pub fn is_url_incognito(&self, app_name: &str, url: &str) -> bool {
+ if url.is_empty() {
+ return false;
+ }
+ let cache = self.cache.lock().unwrap_or_else(|e| e.into_inner());
+ if let Some(entry) = cache.as_ref() {
+ if entry.app_name.eq_ignore_ascii_case(app_name)
+ && entry.timestamp.elapsed() < CACHE_TTL
+ {
+ return entry.has_incognito_url(url);
+ }
+ }
+ false
+ }
}
impl IncognitoDetector for MacOSIncognitoDetector {
fn is_incognito(&self, app_name: &str, _process_id: i32, window_title: &str) -> bool {
// Strategy 1: AppleScript query for Chromium browsers — checks all
- // windows and matches by title, so it works even when the incognito
- // window is not in front.
+ // windows and matches by title (+ tab titles/URLs for Arc).
if Self::is_chromium_browser(app_name) {
if let Some(is_private) = self.check_with_cache(app_name, window_title) {
return is_private;
@@ -219,6 +328,11 @@ impl IncognitoDetector for MacOSIncognitoDetector {
// Strategy 2: Localized title matching (all browsers).
is_title_private(window_title)
}
+
+ fn is_url_incognito(&self, app_name: &str, url: &str) -> bool {
+ // Delegate to the inherent method which checks the batch cache.
+ MacOSIncognitoDetector::is_url_incognito(self, app_name, url)
+ }
}
#[cfg(test)]
@@ -240,6 +354,14 @@ mod tests {
assert!(!MacOSIncognitoDetector::is_chromium_browser("TextEdit"));
}
+ #[test]
+ fn test_is_arc() {
+ assert!(MacOSIncognitoDetector::is_arc("Arc"));
+ assert!(MacOSIncognitoDetector::is_arc("arc"));
+ assert!(!MacOSIncognitoDetector::is_arc("Google Chrome"));
+ assert!(!MacOSIncognitoDetector::is_arc("ArcGIS")); // should not match
+ }
+
#[test]
fn test_applescript_app_name_mapping() {
assert_eq!(applescript_app_name("Chrome"), "Google Chrome");
@@ -261,76 +383,270 @@ mod tests {
fn test_fallback_to_title_for_safari() {
let detector = MacOSIncognitoDetector::new();
// Safari private windows don't change title, so this returns false.
- // That's a known limitation documented in the module.
assert!(!detector.is_incognito("Safari", 0, "Apple"));
}
#[test]
- fn test_batch_cache_reuse() {
+ fn test_batch_cache_with_window_titles() {
let detector = MacOSIncognitoDetector::new();
- // Seed batch cache with known incognito titles.
+ // Seed cache with known incognito window titles.
{
let mut cache = detector.cache.lock().unwrap();
- let mut titles = HashSet::new();
- titles.insert("Secret Page".to_string());
- titles.insert("Dog".to_string());
*cache = Some(BatchCache {
app_name: "Google Chrome".to_string(),
- incognito_titles: titles,
+ incognito_window_titles: {
+ let mut s = HashSet::new();
+ s.insert("Secret Page".to_string());
+ s.insert("Dog".to_string());
+ s
+ },
+ incognito_tab_titles: HashSet::new(),
+ incognito_tab_urls: HashSet::new(),
timestamp: Instant::now(),
});
}
- // Both incognito titles should be detected without osascript.
+ // Both incognito titles should be detected.
assert!(detector.is_incognito("Google Chrome", 0, "Dog"));
assert!(detector.is_incognito("Google Chrome", 0, "Secret Page"));
- // Normal title should return false from cache.
+ // Normal title should return false.
assert!(!detector.is_incognito("Google Chrome", 0, "GitHub"));
}
#[test]
- fn test_batch_cache_different_app_misses() {
+ fn test_arc_tab_title_matching() {
+ // Arc reports "Space 1" as window_name in a11y, but the actual page
+ // title is "The Browser Company". The cache should store tab titles
+ // from the AppleScript query, so matching by tab title works.
+ let detector = MacOSIncognitoDetector::new();
+
+ {
+ let mut cache = detector.cache.lock().unwrap();
+ *cache = Some(BatchCache {
+ app_name: "Arc".to_string(),
+ incognito_window_titles: {
+ let mut s = HashSet::new();
+ s.insert("The Browser Company".to_string());
+ s
+ },
+ incognito_tab_titles: {
+ let mut s = HashSet::new();
+ s.insert("The Browser Company - YouTube".to_string());
+ s.insert("Secret Doc - Google Docs".to_string());
+ s
+ },
+ incognito_tab_urls: {
+ let mut s = HashSet::new();
+ s.insert("https://www.youtube.com/c/TheBrowserCompany".to_string());
+ s.insert("https://docs.google.com/secret".to_string());
+ s
+ },
+ timestamp: Instant::now(),
+ });
+ }
+
+ // Window title from AppleScript matches
+ assert!(detector.is_incognito("Arc", 0, "The Browser Company"));
+ // Tab title matches (this is the key fix - tab title != window title in Arc)
+ assert!(detector.is_incognito("Arc", 0, "The Browser Company - YouTube"));
+ assert!(detector.is_incognito("Arc", 0, "Secret Doc - Google Docs"));
+ // Space name from a11y tree does NOT match (expected — but URL check will catch it)
+ assert!(!detector.is_incognito("Arc", 0, "Space 1"));
+ // Normal window should not be flagged
+ assert!(!detector.is_incognito("Arc", 0, "Google Meet"));
+ }
+
+ #[test]
+ fn test_arc_url_matching() {
+ let detector = MacOSIncognitoDetector::new();
+
+ {
+ let mut cache = detector.cache.lock().unwrap();
+ *cache = Some(BatchCache {
+ app_name: "Arc".to_string(),
+ incognito_window_titles: {
+ let mut s = HashSet::new();
+ s.insert("The Browser Company".to_string());
+ s
+ },
+ incognito_tab_titles: HashSet::new(),
+ incognito_tab_urls: {
+ let mut s = HashSet::new();
+ s.insert("https://www.youtube.com/c/TheBrowserCompany".to_string());
+ s.insert("https://secret-site.com/page".to_string());
+ s
+ },
+ timestamp: Instant::now(),
+ });
+ }
+
+ // URL matching works even when window title is "Space 1"
+ assert!(detector.is_url_incognito("Arc", "https://www.youtube.com/c/TheBrowserCompany"));
+ assert!(detector.is_url_incognito("Arc", "https://secret-site.com/page"));
+ // Non-incognito URL
+ assert!(!detector.is_url_incognito("Arc", "https://meet.google.com/landing"));
+ // Empty URL
+ assert!(!detector.is_url_incognito("Arc", ""));
+ // Wrong app name (cache miss)
+ assert!(!detector.is_url_incognito("Google Chrome", "https://www.youtube.com/c/TheBrowserCompany"));
+ }
+
+ #[test]
+ fn test_cache_different_app_misses() {
let detector = MacOSIncognitoDetector::new();
- // Seed cache for Chrome.
{
let mut cache = detector.cache.lock().unwrap();
- let mut titles = HashSet::new();
- titles.insert("Dog".to_string());
*cache = Some(BatchCache {
app_name: "Google Chrome".to_string(),
- incognito_titles: titles,
+ incognito_window_titles: {
+ let mut s = HashSet::new();
+ s.insert("Dog".to_string());
+ s
+ },
+ incognito_tab_titles: HashSet::new(),
+ incognito_tab_urls: HashSet::new(),
timestamp: Instant::now(),
});
}
- // Different app should miss cache.
+ // Different app should miss cache and fall through to osascript or title check
let result = detector.check_with_cache("Arc", "Dog");
- // Result depends on whether Arc is running.
+ // Result depends on whether Arc is running
if let Some(val) = result {
let _ = val;
}
}
#[test]
- fn test_batch_cache_expiry() {
+ fn test_cache_expiry() {
let detector = MacOSIncognitoDetector::new();
- // Seed with an expired entry.
{
let mut cache = detector.cache.lock().unwrap();
*cache = Some(BatchCache {
app_name: "Google Chrome".to_string(),
- incognito_titles: HashSet::new(),
+ incognito_window_titles: HashSet::new(),
+ incognito_tab_titles: HashSet::new(),
+ incognito_tab_urls: HashSet::new(),
timestamp: Instant::now() - Duration::from_secs(10),
});
}
- // Cache is expired — will re-query or fall back.
+ // Cache is expired — will re-query or fall back
let result = detector.check_with_cache("Google Chrome", "Dog");
if let Some(val) = result {
let _ = val;
}
}
+
+ #[test]
+ fn test_url_check_with_expired_cache() {
+ let detector = MacOSIncognitoDetector::new();
+
+ {
+ let mut cache = detector.cache.lock().unwrap();
+ *cache = Some(BatchCache {
+ app_name: "Arc".to_string(),
+ incognito_window_titles: HashSet::new(),
+ incognito_tab_titles: HashSet::new(),
+ incognito_tab_urls: {
+ let mut s = HashSet::new();
+ s.insert("https://secret.com".to_string());
+ s
+ },
+ timestamp: Instant::now() - Duration::from_secs(10),
+ });
+ }
+
+ // Expired cache should return false (not stale data)
+ assert!(!detector.is_url_incognito("Arc", "https://secret.com"));
+ }
+
+ #[test]
+ fn test_arc_multiple_incognito_windows() {
+ let detector = MacOSIncognitoDetector::new();
+
+ {
+ let mut cache = detector.cache.lock().unwrap();
+ *cache = Some(BatchCache {
+ app_name: "Arc".to_string(),
+ incognito_window_titles: {
+ let mut s = HashSet::new();
+ s.insert("Page A".to_string());
+ s.insert("Page B".to_string());
+ s
+ },
+ incognito_tab_titles: {
+ let mut s = HashSet::new();
+ s.insert("Tab A1".to_string());
+ s.insert("Tab A2".to_string());
+ s.insert("Tab B1".to_string());
+ s
+ },
+ incognito_tab_urls: {
+ let mut s = HashSet::new();
+ s.insert("https://a1.com".to_string());
+ s.insert("https://a2.com".to_string());
+ s.insert("https://b1.com".to_string());
+ s
+ },
+ timestamp: Instant::now(),
+ });
+ }
+
+ // All incognito entries should match
+ assert!(detector.is_incognito("Arc", 0, "Page A"));
+ assert!(detector.is_incognito("Arc", 0, "Tab A1"));
+ assert!(detector.is_incognito("Arc", 0, "Tab B1"));
+ assert!(detector.is_url_incognito("Arc", "https://a1.com"));
+ assert!(detector.is_url_incognito("Arc", "https://b1.com"));
+ // Normal entries should not
+ assert!(!detector.is_incognito("Arc", 0, "Google Meet"));
+ assert!(!detector.is_url_incognito("Arc", "https://meet.google.com"));
+ }
+
+ // --- Live test: only runs if Arc is actually running with incognito windows ---
+ // Run with: cargo test -p screenpipe-a11y -- --ignored test_live_arc
+ #[test]
+ #[ignore]
+ fn test_live_arc_incognito_detection() {
+ let detector = MacOSIncognitoDetector::new();
+
+ // This will actually call AppleScript against Arc
+ let data = MacOSIncognitoDetector::query_incognito_data("Arc");
+ match data {
+ Some((window_titles, tab_titles, tab_urls)) => {
+ println!("Arc incognito window titles: {:?}", window_titles);
+ println!("Arc incognito tab titles: {:?}", tab_titles);
+ println!("Arc incognito tab URLs: {:?}", tab_urls);
+
+ if window_titles.is_empty() {
+ println!("No incognito windows found — open one in Arc to test");
+ } else {
+ // Verify that the detector works with the live data
+ for title in &window_titles {
+ assert!(
+ detector.is_incognito("Arc", 0, title),
+ "Window title '{}' should be detected as incognito",
+ title
+ );
+ }
+
+ // After is_incognito call, cache should be populated
+ for url in &tab_urls {
+ assert!(
+ detector.is_url_incognito("Arc", url),
+ "URL '{}' should be detected as incognito",
+ url
+ );
+ }
+ }
+ }
+ None => {
+ println!("Arc is not running or AppleScript failed — skipping live test");
+ }
+ }
+ }
}
diff --git a/crates/screenpipe-a11y/src/incognito/mod.rs b/crates/screenpipe-a11y/src/incognito/mod.rs
index 600cf4992..facac7d33 100644
--- a/crates/screenpipe-a11y/src/incognito/mod.rs
+++ b/crates/screenpipe-a11y/src/incognito/mod.rs
@@ -53,6 +53,18 @@ pub trait IncognitoDetector: Send + Sync {
/// definitely normal, or falls back to title-based detection when the
/// platform API is unavailable for this browser.
fn is_incognito(&self, app_name: &str, process_id: i32, window_title: &str) -> bool;
+
+ /// Check whether a browser URL belongs to an incognito tab.
+ ///
+ /// This is a fallback for browsers like Arc where the accessibility tree
+ /// reports a different window name (Space name) than the AppleScript
+ /// window title. The URL is extracted after the tree walk and can be
+ /// checked against the cached incognito tab URLs.
+ ///
+ /// Default implementation returns `false` (no URL-based detection).
+ fn is_url_incognito(&self, _app_name: &str, _url: &str) -> bool {
+ false
+ }
}
/// Create the platform-appropriate incognito detector.
diff --git a/crates/screenpipe-a11y/src/tree/macos.rs b/crates/screenpipe-a11y/src/tree/macos.rs
index 2e228d73d..256f67179 100644
--- a/crates/screenpipe-a11y/src/tree/macos.rs
+++ b/crates/screenpipe-a11y/src/tree/macos.rs
@@ -336,6 +336,19 @@ impl MacosTreeWalker {
None
};
+ // Second-pass incognito check using browser URL (catches Arc where
+ // the a11y window name is the Space name, not the page title).
+ // The first check at line ~266 uses window_title which may not match
+ // for Arc. This URL-based check uses the cached incognito tab URLs
+ // populated by the earlier is_incognito() call.
+ if self.config.ignore_incognito_windows {
+ if let Some(ref url) = browser_url {
+ if self.incognito_detector.is_url_incognito(&app_name, url) {
+ return Ok(TreeWalkResult::Skipped(SkipReason::Incognito));
+ }
+ }
+ }
+
debug!(
"tree walk: app={}, window={}, nodes={}, text_len={}, url={:?}, duration={:?}",
app_name,