From bbe57b476493f971f2541d692fa6b1ae238b6c40 Mon Sep 17 00:00:00 2001 From: "Dhanji R. Prasanna" Date: Mon, 15 Dec 2025 17:36:34 +1100 Subject: [PATCH] Fix ChromeDriver session hanging when Chrome is already running - Add unique user-data-dir per process to avoid profile conflicts - Add 30-second timeout to connection attempts to prevent indefinite hangs - Fix borrow checker issue with ClientBuilder The session creation was hanging because ChromeDriver was trying to use the same profile as the running Chrome browser. Using a unique temp directory (/tmp/g3-chrome-{pid}) isolates the headless session. --- crates/g3-computer-control/src/webdriver/chrome.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/g3-computer-control/src/webdriver/chrome.rs b/crates/g3-computer-control/src/webdriver/chrome.rs index 5e706e9..6830ab3 100644 --- a/crates/g3-computer-control/src/webdriver/chrome.rs +++ b/crates/g3-computer-control/src/webdriver/chrome.rs @@ -44,6 +44,8 @@ impl ChromeDriver { chrome_options.insert( "args".to_string(), Value::Array(vec![ + // Use a unique temp directory to avoid conflicts with running Chrome instances + Value::String(format!("--user-data-dir=/tmp/g3-chrome-{}", std::process::id())), Value::String("--headless=new".to_string()), Value::String("--disable-gpu".to_string()), Value::String("--no-sandbox".to_string()), @@ -62,11 +64,16 @@ impl ChromeDriver { Value::Object(chrome_options), ); - let client = ClientBuilder::native() + // Use a timeout for the connection attempt to avoid hanging indefinitely + let mut builder = ClientBuilder::native(); + let connect_future = builder .capabilities(caps) - .connect(&url) + .connect(&url); + + let client = tokio::time::timeout(Duration::from_secs(30), connect_future) .await - .context("Failed to connect to ChromeDriver. Make sure ChromeDriver is running and Chrome is installed.")?; + .context("Connection to ChromeDriver timed out after 30 seconds")? + .context("Failed to connect to ChromeDriver")?; Ok(Self { client }) }