From 7a72f72d2959a5d0fd76d00d80ee6a230b15cd62 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Sun, 8 Oct 2023 20:48:06 -0300 Subject: [PATCH] Fixes wrong error message when running as root in sandbox mode (#406) * Fixes wrong error message when running as root in sandbox mode When running as root the error reported is misleading: There are no available ports between 8000 and 9000 for debugging This commit fixes this and reports the proper (new) error RunningAsRootWithoutNoSandbox: You need to set the sandbox(false) option when running as root * Fixes cargo check error for a mut where not needed --- src/browser/process.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/browser/process.rs b/src/browser/process.rs index 902f1fba..32b47b37 100644 --- a/src/browser/process.rs +++ b/src/browser/process.rs @@ -50,6 +50,8 @@ enum ChromeLaunchError { NoAvailablePorts, #[error("The chosen debugging port is already in use")] DebugPortInUse, + #[error("You need to set the sandbox(false) option when running as root")] + RunningAsRootWithoutNoSandbox, } #[cfg(windows)] @@ -417,6 +419,7 @@ impl Process { R: Read, { let port_taken_re = Regex::new(r"ERROR.*bind\(\)")?; + let root_sandbox = "Running as root without --no-sandbox is not supported"; let re = Regex::new(r"listening on (.*/devtools/browser/.*)$")?; @@ -430,6 +433,10 @@ impl Process { let chrome_output = line?; trace!("Chrome output: {}", chrome_output); + if chrome_output.contains(root_sandbox) { + return Err(ChromeLaunchError::RunningAsRootWithoutNoSandbox {}.into()); + } + if port_taken_re.is_match(&chrome_output) { return Err(ChromeLaunchError::DebugPortInUse {}.into()); }