Function headless_chrome::browser::default_executable
source · Expand description
Returns the path to Chrome’s executable.
If the CHROME
environment variable is set, default_executable
will
use it as the default path. Otherwise, the filenames google-chrome-stable
chromium
, chromium-browser
, chrome
and chrome-browser
are
searched for in standard places. If that fails,
/Applications/Google Chrome.app/...
(on MacOS) or the registry (on Windows)
is consulted. If all of the above fail, an error is returned.
Examples found in repository?
More examples
src/browser/process.rs (line 257)
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
pub fn new(mut launch_options: LaunchOptions) -> Result<Self> {
if launch_options.path.is_none() {
#[cfg(feature = "fetch")]
{
let fetch = Fetcher::new(launch_options.fetcher_options.clone())?;
launch_options.path = Some(fetch.fetch()?);
}
#[cfg(not(feature = "fetch"))]
{
launch_options.path = Some(default_executable().map_err(|e| anyhow!("{}", e))?);
}
}
let mut process = Self::start_process(&launch_options)?;
info!("Started Chrome. PID: {}", process.0.id());
let url;
let mut attempts = 0;
loop {
if attempts > 10 {
return Err(ChromeLaunchError::NoAvailablePorts {}.into());
}
match Self::ws_url_from_output(process.0.borrow_mut()) {
Ok(debug_ws_url) => {
url = debug_ws_url;
debug!("Found debugging WS URL: {:?}", url);
break;
}
Err(error) => {
trace!("Problem getting WebSocket URL from Chrome: {}", error);
if launch_options.port.is_none() {
process = Self::start_process(&launch_options)?;
} else {
return Err(error);
}
}
}
trace!(
"Trying again to find available debugging port. Attempts: {}",
attempts
);
attempts += 1;
}
let mut child = process.0.borrow_mut();
child.stderr = None;
Ok(Self {
child_process: process,
debug_ws_url: url,
})
}