fix: properly handle headless mode

This commit is contained in:
zhom
2026-04-22 00:39:02 +04:00
parent 3fd0642185
commit 5c4e3e7318
3 changed files with 12 additions and 4 deletions
+3 -1
View File
@@ -156,7 +156,7 @@ impl BrowserRunner {
url: Option<String>,
_local_proxy_settings: Option<&ProxySettings>,
remote_debugging_port: Option<u16>,
_headless: bool,
headless: bool,
) -> Result<BrowserProfile, Box<dyn std::error::Error + Send + Sync>> {
// 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<dyn std::error::Error + Send + Sync> {
@@ -592,6 +593,7 @@ impl BrowserRunner {
profile.ephemeral,
&extension_paths,
remote_debugging_port,
headless,
)
.await
.map_err(|e| -> Box<dyn std::error::Error + Send + Sync> {
+6 -2
View File
@@ -207,6 +207,7 @@ impl CamoufoxManager {
profile_path: &str,
config: &CamoufoxConfig,
url: Option<&str>,
headless: bool,
) -> Result<CamoufoxLaunchResult, Box<dyn std::error::Error + Send + Sync>> {
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<String>,
override_profile_path: Option<std::path::PathBuf>,
headless: bool,
) -> Result<CamoufoxLaunchResult, String> {
// 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}"))
+3 -1
View File
@@ -504,6 +504,7 @@ impl WayfernManager {
ephemeral: bool,
extension_paths: &[String],
remote_debugging_port: Option<u16>,
headless: bool,
) -> Result<WayfernLaunchResult, Box<dyn std::error::Error + Send + Sync>> {
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
}