From 5c4e3e7318f0993559182fce040c0c96ed9ab4fa Mon Sep 17 00:00:00 2001 From: zhom <2717306+zhom@users.noreply.github.com> Date: Wed, 22 Apr 2026 00:39:02 +0400 Subject: [PATCH] fix: properly handle headless mode --- src-tauri/src/browser_runner.rs | 4 +++- src-tauri/src/camoufox_manager.rs | 8 ++++++-- src-tauri/src/wayfern_manager.rs | 4 +++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/browser_runner.rs b/src-tauri/src/browser_runner.rs index a791f10..4726f17 100644 --- a/src-tauri/src/browser_runner.rs +++ b/src-tauri/src/browser_runner.rs @@ -156,7 +156,7 @@ impl BrowserRunner { url: Option, _local_proxy_settings: Option<&ProxySettings>, remote_debugging_port: Option, - _headless: bool, + headless: bool, ) -> Result> { // Handle Camoufox profiles using CamoufoxManager if profile.browser == "camoufox" { @@ -335,6 +335,7 @@ impl BrowserRunner { camoufox_config, url, override_profile_path, + headless, ) .await .map_err(|e| -> Box { @@ -592,6 +593,7 @@ impl BrowserRunner { profile.ephemeral, &extension_paths, remote_debugging_port, + headless, ) .await .map_err(|e| -> Box { diff --git a/src-tauri/src/camoufox_manager.rs b/src-tauri/src/camoufox_manager.rs index 3ba975e..22eea7e 100644 --- a/src-tauri/src/camoufox_manager.rs +++ b/src-tauri/src/camoufox_manager.rs @@ -207,6 +207,7 @@ impl CamoufoxManager { profile_path: &str, config: &CamoufoxConfig, url: Option<&str>, + headless: bool, ) -> Result> { let custom_config = if let Some(existing_fingerprint) = &config.fingerprint { log::info!("Using existing fingerprint from profile metadata"); @@ -251,8 +252,9 @@ impl CamoufoxManager { args.push(url.to_string()); } - // Add headless flag for tests - if std::env::var("CAMOUFOX_HEADLESS").is_ok() { + // Add headless flag when requested via the API or via the CAMOUFOX_HEADLESS + // env var (used by integration tests) + if headless || std::env::var("CAMOUFOX_HEADLESS").is_ok() { args.push("--headless".to_string()); } @@ -617,6 +619,7 @@ impl CamoufoxManager { config: CamoufoxConfig, url: Option, override_profile_path: Option, + headless: bool, ) -> Result { // Get profile path let profile_path = if let Some(ref override_path) = override_profile_path { @@ -716,6 +719,7 @@ impl CamoufoxManager { &profile_path_str, &config, url.as_deref(), + headless, ) .await .map_err(|e| format!("Failed to launch Camoufox: {e}")) diff --git a/src-tauri/src/wayfern_manager.rs b/src-tauri/src/wayfern_manager.rs index 39772ee..07fa9a9 100644 --- a/src-tauri/src/wayfern_manager.rs +++ b/src-tauri/src/wayfern_manager.rs @@ -504,6 +504,7 @@ impl WayfernManager { ephemeral: bool, extension_paths: &[String], remote_debugging_port: Option, + headless: bool, ) -> Result> { let executable_path = BrowserRunner::instance() .get_browser_executable_path(profile) @@ -672,7 +673,7 @@ impl WayfernManager { let profile_path_ref = std::path::Path::new(profile_path); let mut launcher = chromium.persistent_context_launcher(profile_path_ref); launcher = launcher.executable(executable_path.as_ref()); - launcher = launcher.headless(false); + launcher = launcher.headless(headless); launcher = launcher.chromium_sandbox(true); launcher = launcher.args(&args); launcher = launcher.timeout(0.0); @@ -1151,6 +1152,7 @@ impl WayfernManager { profile.ephemeral, &[], None, + false, ) .await }