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
feat: capture browser url in windows (#1489)
tribhuwan21f27fdedc0e
diff --git a/screenpipe-vision/Cargo.toml b/screenpipe-vision/Cargo.tomlindex 365b856e1..55e4fde3a 100644--- a/screenpipe-vision/Cargo.toml+++ b/screenpipe-vision/Cargo.toml@@ -85,6 +85,7 @@ name = "screenpipe-vision-websocket"path = "examples/websocket.rs"[target.'cfg(target_os = "windows")'.dependencies]+uiautomation = { version = "0.16.1" }windows = { version = "0.58", features = ["Graphics_Imaging","Media_Ocr",diff --git a/screenpipe-vision/src/browser_utils/mod.rs b/screenpipe-vision/src/browser_utils/mod.rsindex fb1cedf93..e972420ff 100644--- a/screenpipe-vision/src/browser_utils/mod.rs+++ b/screenpipe-vision/src/browser_utils/mod.rs@@ -10,7 +10,10 @@ pub fn create_url_detector() -> Box<dyn BrowserUrlDetector> {#[cfg(target_os = "macos")]return Box::new(MacOSUrlDetector::new());- #[cfg(not(target_os = "macos"))]+ #[cfg(target_os = "windows")]+ return Box::new(WindowsUrlDetector::new());++ #[cfg(target_os = "linux")]return Box::new(UnsupportedUrlDetector::new());}@@ -33,4 +36,10 @@ impl BrowserUrlDetector for UnsupportedUrlDetector {#[cfg(target_os = "macos")]mod macos;#[cfg(target_os = "macos")]-pub use macos::MacOSUrlDetector;\ No newline at end of file+pub use macos::MacOSUrlDetector;++#[cfg(target_os = "windows")]+mod windows;+#[cfg(target_os = "windows")]+pub use windows::WindowsUrlDetector;+diff --git a/screenpipe-vision/src/browser_utils/windows.rs b/screenpipe-vision/src/browser_utils/windows.rsnew file mode 100644index 000000000..e4a5cf5eb--- /dev/null+++ b/screenpipe-vision/src/browser_utils/windows.rs@@ -0,0 +1,88 @@+use reqwest::Error;+use anyhow::{Result, anyhow};+use tracing::{debug, error};+use reqwest::blocking::Client;+use uiautomation::variants::Variant;+use uiautomation::types::UIProperty::ProcessId;+use uiautomation::{UIAutomation, controls::ControlType};+use uiautomation::types::{UIProperty, TreeScope};++use super::BrowserUrlDetector;++pub struct WindowsUrlDetector;++impl WindowsUrlDetector {+ pub fn new() -> Self {+ Self+ }++ fn validate_url(url: &str) -> Result<bool, Error> {+ let client = Client::new();+ let response = client.get(url).send();+ match response {+ Ok(_) => Ok(true),+ Err(_) => Ok(false),+ }+ }++ fn get_active_url_from_window(pid: i32) -> Result<Option<String>> {+ let automation = UIAutomation::new().unwrap();+ let root_ele = automation.get_root_element().unwrap();+ let condition = automation.create_property_condition(+ ProcessId,+ Variant::from(pid as i32),+ None+ ).unwrap();++ match root_ele.find_first(TreeScope::Subtree, &condition) {+ Ok(ele) => {+ let control_condition = automation.create_property_condition(+ UIProperty::ControlType,+ Variant::from(ControlType::Edit as i32),+ None,+ ).unwrap();++ if let Ok(address_bar) = ele.find_first(TreeScope::Subtree, &control_condition){+ debug!("address bar: {:?}", address_bar);+ if let Ok(value) = address_bar.get_property_value(UIProperty::ValueValue) {+ if let Ok(url) = value.get_string() {+ if !url.is_empty() {+ debug!("found url: {}", url);+ if !url.starts_with("http://") && !url.starts_with("https://") {+ let full_url = format!("https://{}", url);+ debug!("reconstructed url: {}", full_url);+ if Self::validate_url(&full_url).unwrap_or(false) {+ debug!("validated url: {}", full_url);+ return Ok(Some(full_url));+ } else {+ debug!("invalid url, might be some search text: {}", url);+ }+ } else {+ if Self::validate_url(&url).unwrap_or(false) {+ debug!("validated url: {}", url);+ return Ok(Some(url));+ } else {+ debug!("invalid url, might be some search text: {}", url);+ }+ return Ok(Some(url));+ }+ }+ }+ }+ }+ }+ Err(e) => {+ error!("failed to find edit bar: {}", e);+ return Err(anyhow!("failed to find edit bar: {}", e));+ }+ }+ Ok(None)+ }+}++impl BrowserUrlDetector for WindowsUrlDetector {+ fn get_active_url(&self, _app_name: &str, process_id: i32) -> Result<Option<String>> {+ return Self::get_active_url_from_window(process_id);+ }+}+diff --git a/screenpipe-vision/src/core.rs b/screenpipe-vision/src/core.rsindex 78f2a4222..6df6fd7fe 100644--- a/screenpipe-vision/src/core.rs+++ b/screenpipe-vision/src/core.rs@@ -285,7 +285,7 @@ pub async fn process_ocr_task(for captured_window in window_images {let app_name = captured_window.app_name.clone();- let browser_url = if cfg!(target_os = "macos")+ let browser_url = if cfg!(not(target_os = "linux"))&& captured_window.is_focused&& BROWSER_NAMES.iter()