diff --git a/cli/src/native/cdp/chrome.rs b/cli/src/native/cdp/chrome.rs index 81d9926..d810aec 100644 --- a/cli/src/native/cdp/chrome.rs +++ b/cli/src/native/cdp/chrome.rs @@ -180,6 +180,10 @@ fn build_chrome_args(options: &LaunchOptions) -> Result { args.push("--no-sandbox".to_string()); } + if should_disable_dev_shm(&args) { + args.push("--disable-dev-shm-usage".to_string()); + } + Ok(ChromeArgs { args, temp_user_data_dir, @@ -531,6 +535,36 @@ fn should_disable_sandbox(existing_args: &[String]) -> bool { false } +/// Returns true if Chrome should use disk instead of /dev/shm for shared memory. +/// On CI runners and containers, /dev/shm is often too small (64MB default), +/// which causes Chrome to crash mid-session. +fn should_disable_dev_shm(existing_args: &[String]) -> bool { + if existing_args.iter().any(|a| a == "--disable-dev-shm-usage") { + return false; + } + + if std::env::var("CI").is_ok() { + return true; + } + + #[cfg(unix)] + { + if unsafe { libc::geteuid() } == 0 { + return true; + } + if Path::new("/.dockerenv").exists() || Path::new("/run/.containerenv").exists() { + return true; + } + if let Ok(cgroup) = std::fs::read_to_string("/proc/1/cgroup") { + if cgroup.contains("docker") || cgroup.contains("kubepods") || cgroup.contains("lxc") { + return true; + } + } + } + + false +} + /// Search Playwright's browser cache for a Chromium binary. /// Legacy fallback for users who previously installed Chromium via Playwright. fn find_playwright_chromium() -> Option {