From d600b600b8e52bc3070c2502dd6e13579472e82f Mon Sep 17 00:00:00 2001 From: "Dhanji R. Prasanna" Date: Sat, 17 Jan 2026 09:48:10 +0530 Subject: [PATCH] Always keep chromedriver running for faster subsequent startups Removed the persistent_chrome config flag - chromedriver is now always kept running after webdriver_quit. This eliminates startup latency for subsequent WebDriver sessions. Safaridriver is still killed on quit since it doesn't benefit from persistence in the same way. Updated quit message to correctly indicate chromedriver remains running. --- config.example.toml | 1 - crates/g3-config/src/lib.rs | 4 ---- crates/g3-core/src/tools/webdriver.rs | 20 ++++++++------------ 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/config.example.toml b/config.example.toml index 8845749..49e3551 100644 --- a/config.example.toml +++ b/config.example.toml @@ -80,4 +80,3 @@ model = "claude-sonnet-4-5" # browser = "chrome-headless" # Default. Alternative: "safari" # chrome_binary = "/path/to/chrome" # Optional: custom Chrome path # chromedriver_binary = "/path/to/driver" # Optional: custom ChromeDriver path -# persistent_chrome = true # Keep chromedriver running between sessions for faster startup diff --git a/crates/g3-config/src/lib.rs b/crates/g3-config/src/lib.rs index adcad7d..c57e727 100644 --- a/crates/g3-config/src/lib.rs +++ b/crates/g3-config/src/lib.rs @@ -179,10 +179,6 @@ pub struct WebDriverConfig { pub chromedriver_binary: Option, #[serde(default)] pub browser: WebDriverBrowser, - #[serde(default)] - /// Keep chromedriver running after session ends for faster subsequent startups - /// When true, chromedriver process is not killed on webdriver_quit - pub persistent_chrome: bool, } impl Default for AgentConfig { diff --git a/crates/g3-core/src/tools/webdriver.rs b/crates/g3-core/src/tools/webdriver.rs index 4fa7bc5..029d819 100644 --- a/crates/g3-core/src/tools/webdriver.rs +++ b/crates/g3-core/src/tools/webdriver.rs @@ -644,13 +644,13 @@ pub async fn execute_webdriver_quit( Ok(_) => { debug!("WebDriver session closed successfully"); - // Kill the driver process (unless persistent_chrome is enabled for Chrome) + // For Chrome, always keep chromedriver running for faster subsequent startups + // For Safari, kill safaridriver as it doesn't benefit from persistence use g3_config::WebDriverBrowser; let is_chrome = matches!(&ctx.config.webdriver.browser, WebDriverBrowser::ChromeHeadless); - let keep_running = is_chrome && ctx.config.webdriver.persistent_chrome; - if keep_running { - debug!("Keeping chromedriver running (persistent_chrome enabled)"); + if is_chrome { + debug!("Keeping chromedriver running for reuse"); // Still take the process handle but don't kill it let _ = ctx.webdriver_process.write().await.take(); } else if let Some(mut process) = ctx.webdriver_process.write().await.take() { @@ -659,17 +659,13 @@ pub async fn execute_webdriver_quit( } else { debug!("Driver process terminated"); } - } + } // Return appropriate message based on browser type - let driver_name = match &ctx.config.webdriver.browser { - WebDriverBrowser::Safari => "safaridriver", - WebDriverBrowser::ChromeHeadless => "chromedriver", - }; - if keep_running { - Ok(format!("✅ WebDriver session closed ({} still running for reuse)", driver_name)) + if is_chrome { + Ok("✅ WebDriver session closed (chromedriver still running for reuse)".to_string()) } else { - Ok(format!("✅ WebDriver session closed and {} stopped", driver_name)) + Ok("✅ WebDriver session closed and safaridriver stopped".to_string()) } } Err(e) => Ok(format!("❌ Failed to quit WebDriver: {}", e)),