Selenium Chrome Driver provides WebDriver implementation for Google Chrome with Chrome DevTools Protocol support, network conditions simulation, permissions management, media casting capabilities, and Chrome-specific service configuration.
—
The ChromiumDriver extends standard WebDriver functionality with Chromium-specific features including script pinning, authentication handling, and enhanced logging capabilities.
Retrieve the current browser capabilities with Chromium-specific enhancements.
public Capabilities getCapabilities();Returns: Capabilities - Browser capabilities including CDP and BiDi endpoints when available
Usage Example:
Capabilities caps = driver.getCapabilities();
String browserVersion = caps.getBrowserVersion();
String cdpEndpoint = (String) caps.getCapability("se:cdp");Pin JavaScript scripts for reuse across page navigations and refreshes.
public ScriptKey pin(String script);Parameters:
script (String): JavaScript code to pin for reuseReturns: ScriptKey - Reference to the pinned script
Usage Example:
ChromiumDriver driver = new ChromiumDriver(commandExecutor, capabilities, "chrome");
// Pin a script for reuse
ScriptKey scriptKey = driver.pin("return document.title;");
// Execute the pinned script
String title = (String) driver.executeScript(scriptKey);Retrieve all currently pinned scripts.
public Set<ScriptKey> getPinnedScripts();Returns: Set<ScriptKey> - Collection of all pinned script references
Remove a pinned script from memory.
public void unpin(ScriptKey key);Parameters:
key (ScriptKey): Reference to the script to unpinThrows: JavascriptException if the script key is not found
Execute a previously pinned script with optional arguments.
public Object executeScript(ScriptKey key, Object... args);Parameters:
key (ScriptKey): Reference to the pinned scriptargs (Object...): Arguments to pass to the scriptReturns: Object - Result of script execution
Throws: JavascriptException if the script key is not found
Register an authentication handler for specific URL patterns.
public void register(Predicate<URI> whenThisMatches, Supplier<Credentials> useTheseCredentials);Parameters:
whenThisMatches (Predicate<URI>): Predicate to determine when to apply authenticationuseTheseCredentials (Supplier<Credentials>): Supplier providing credentialsUsage Example:
import org.openqa.selenium.Credentials;
import java.net.URI;
driver.register(
uri -> uri.getHost().equals("secure.example.com"),
() -> new Credentials("username", "password")
);Register a listener for specific log event types.
public <X> void onLogEvent(EventType<X> kind);Parameters:
kind (EventType<X>): Type of log event to listen forUsage Example:
import org.openqa.selenium.logging.EventType;
// Listen for console log events
driver.onLogEvent(EventType.CONSOLE_API);Access browser's local storage.
@Deprecated
public LocalStorage getLocalStorage();Returns: LocalStorage - Interface to local storage operations
Access browser's session storage.
@Deprecated
public SessionStorage getSessionStorage();Returns: SessionStorage - Interface to session storage operations
Get current geolocation.
@Deprecated
public Location location();Returns: Location - Current geolocation
Set browser geolocation.
@Deprecated
public void setLocation(Location location);Parameters:
location (Location): New geolocation to setNote: File detection is not supported for local ChromiumDriver instances.
public void setFileDetector(FileDetector detector);Throws: WebDriverException - Always throws as this is only supported for remote instances
// Script reference for pinned scripts
public class ScriptKey {
public String getIdentifier();
}
// Authentication credentials
public class Credentials {
public Credentials(String username, String password);
public String getUsername();
public String getPassword();
}
// Event types for logging
public abstract class EventType<T> {
public void initializeListener(WebDriver driver);
}
// Geolocation data
public class Location {
public Location(double latitude, double longitude, double altitude);
public double getLatitude();
public double getLongitude();
public double getAltitude();
}Common exceptions that may be thrown:
quit() to properly clean up pinned scripts and resourcesInstall with Tessl CLI
npx tessl i tessl/maven-org-seleniumhq-selenium--selenium-chromium-driver