Implementation:SeleniumHQ Selenium ChromeDriverService CreateDefaultService
| Knowledge Sources | |
|---|---|
| Domains | Browser_Automation, Process_Management, WebDriver |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Concrete tool for managing the chromedriver process lifecycle provided by the Selenium Java library.
Description
The ChromeDriverService class manages the chromedriver OS process, extending the base DriverService class. It provides a Builder pattern for configuring log level, log file, allowed IP addresses, build check settings, and verbose/silent modes. The createDefaultService() factory method constructs a service with default settings, auto-selecting a free port. The service starts the chromedriver binary as a child process and monitors its lifecycle. The Builder reads default values from system properties (e.g., webdriver.chrome.driver, webdriver.chrome.logfile, webdriver.chrome.loglevel) and environment variables (e.g., SE_CHROMEDRIVER).
Usage
Use this class when you need explicit control over the chromedriver process configuration, such as setting a specific port for debugging, enabling verbose logging, or allowing remote connections by IP whitelist. For typical usage, new ChromeDriver() handles service creation automatically.
Code Reference
Source Location
- Repository: Selenium
- File: java/src/org/openqa/selenium/chrome/ChromeDriverService.java
- Lines: L43-348
Signature
public class ChromeDriverService extends DriverService {
public static final String CHROME_DRIVER_NAME = "chromedriver";
public static final String CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver";
public static final String CHROME_DRIVER_EXE_ENVIRONMENT_VARIABLE = "SE_CHROMEDRIVER";
public static ChromeDriverService createDefaultService();
public ChromeDriverService(
@Nullable File executable,
int port,
@Nullable Duration timeout,
@Nullable List<String> args,
@Nullable Map<String, String> environment
) throws IOException;
// Builder pattern
public static class Builder
extends DriverService.Builder<ChromeDriverService, Builder> {
public Builder withAppendLog(boolean appendLog);
public Builder withBuildCheckDisabled(boolean noBuildCheck);
public Builder withLogLevel(@Nullable ChromiumDriverLogLevel logLevel);
public Builder withSilent(boolean silent);
public Builder withVerbose(boolean verbose);
public Builder withAllowedListIps(@Nullable String allowedListIps);
public Builder withReadableTimestamp(@Nullable Boolean readableTimestamp);
}
}
Import
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| executable | File | No | Path to chromedriver binary (auto-resolved if not set) |
| port | int | No | Server port (0 = auto-select free port) |
| timeout | Duration | No | Startup timeout |
| logLevel | ChromiumDriverLogLevel | No | Logging verbosity (OFF, SEVERE, WARNING, INFO, ALL) |
| allowedListIps | String | No | Comma-separated list of allowed remote IPv4 addresses |
| appendLog | boolean | No | Whether to append to the log file rather than overwrite |
| readableTimestamp | Boolean | No | Whether to format log timestamps in a human-readable form |
Outputs
| Name | Type | Description |
|---|---|---|
| service | ChromeDriverService | Running driver service with accessible URL (http://localhost:PORT) |
| getUrl() | URL | Base URL for WebDriver HTTP commands |
Usage Examples
Default Service (Automatic)
// createDefaultService() is called automatically by ChromeDriver()
ChromeDriver driver = new ChromeDriver();
Custom Service with Logging
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
import java.io.File;
ChromeDriverService service = new ChromeDriverService.Builder()
.usingPort(9515)
.withLogLevel(ChromiumDriverLogLevel.ALL)
.withLogFile(new File("/tmp/chromedriver.log"))
.withAppendLog(true)
.withReadableTimestamp(true)
.build();
ChromeDriver driver = new ChromeDriver(service, new ChromeOptions());
// service is automatically stopped when driver.quit() is called
Service with Build Check Disabled
import org.openqa.selenium.chrome.ChromeDriverService;
ChromeDriverService service = new ChromeDriverService.Builder()
.withBuildCheckDisabled(true)
.withAllowedListIps("127.0.0.1,192.168.1.100")
.build();
ChromeDriver driver = new ChromeDriver(service, new ChromeOptions());