Skip to content

Commit

Permalink
Fixes wrong error message when running as root in sandbox mode (rust-…
Browse files Browse the repository at this point in the history
…headless-chrome#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
  • Loading branch information
fcoury authored and pull[bot] committed Oct 9, 2023
1 parent d97bc40 commit 7a72f72
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/browser/process.rs
Expand Up @@ -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)]
Expand Down Expand Up @@ -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/.*)$")?;

Expand All @@ -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());
}
Expand Down

0 comments on commit 7a72f72

Please sign in to comment.