Access to ChromeDriver binary path, version, and running instance information for integration with Selenium and other automation frameworks.
Get the absolute path to the ChromeDriver binary executable.
/**
* Path to the ChromeDriver binary executable
* @type {string}
*/
const path;Usage Examples:
const chromedriver = require('chromedriver');
// Get binary path
console.log('ChromeDriver binary path:', chromedriver.path);
// Example output: '/path/to/node_modules/chromedriver/lib/chromedriver/chromedriver'
// Use with child_process
const { spawn } = require('child_process');
const chromedriverProcess = spawn(chromedriver.path, ['--port=9515']);
// Use with Selenium WebDriver Builder
const webdriver = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const service = new chrome.ServiceBuilder(chromedriver.path);
const driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeService(service)
.build();Platform-Specific Behavior:
chromedriver.exe in the binary directorychromedriver executable in the binary directory// Platform-specific path resolution
const binaryPath = process.platform === 'win32'
? path.join(__dirname, 'chromedriver', 'chromedriver.exe')
: path.join(__dirname, 'chromedriver', 'chromedriver');Get the version of the ChromeDriver binary included with this package.
/**
* Version of the ChromeDriver binary
* @type {string}
*/
const version;Usage Examples:
const chromedriver = require('chromedriver');
// Get version information
console.log('ChromeDriver version:', chromedriver.version);
// Example output: '140.0.7339.80'
// Version compatibility checking
const { compareVersions } = require('compare-versions');
if (compareVersions(chromedriver.version, '120.0.0') >= 0) {
console.log('Using modern ChromeDriver API');
} else {
console.log('Using legacy ChromeDriver API');
}
// Logging for debugging
console.log(`Starting tests with ChromeDriver ${chromedriver.version}`);Access the currently running ChromeDriver process instance for monitoring and control.
/**
* Currently running ChromeDriver process instance
* @type {ChildProcess|null}
*/
const defaultInstance;Usage Examples:
const chromedriver = require('chromedriver');
// Start ChromeDriver
chromedriver.start(['--port=9515']);
// Monitor the running instance
if (chromedriver.defaultInstance) {
console.log('Process ID:', chromedriver.defaultInstance.pid);
console.log('ChromeDriver is running');
// Listen for process events
chromedriver.defaultInstance.on('exit', (code, signal) => {
console.log(`ChromeDriver process exited with code ${code}, signal ${signal}`);
});
chromedriver.defaultInstance.on('error', (error) => {
console.error('ChromeDriver process error:', error);
});
// Check if process is still alive
const isRunning = !chromedriver.defaultInstance.killed;
console.log('Process is running:', isRunning);
}
// After stopping
chromedriver.stop();
console.log('Default instance after stop:', chromedriver.defaultInstance); // nullChromeDriver automatically registers itself with selenium-webdriver when required:
// Automatic registration - just require the package
require('chromedriver');
const webdriver = require('selenium-webdriver');
const driver = new webdriver.Builder()
.forBrowser('chrome')
.build();
// ChromeDriver binary is automatically available to SeleniumFor frameworks that need explicit binary paths:
const chromedriver = require('chromedriver');
const { Builder } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
// Create service with explicit path
const service = new chrome.ServiceBuilder(chromedriver.path)
.setPort(9515)
.build();
const driver = new Builder()
.forBrowser('chrome')
.setChromeService(service)
.build();The package automatically adds the binary directory to the PATH:
// Automatic PATH modification on require
process.env.PATH = path.join(__dirname, 'chromedriver') + path.delimiter + process.env.PATH;This ensures that:
chromedriver from the command lineChromeDriver binaries are downloaded to:
node_modules/chromedriver/lib/chromedriver/
├── chromedriver (macOS/Linux)
└── chromedriver.exe (Windows)If the local binary is not found:
chromedriver command// Fallback logging example
if (!fs.existsSync(chromedriver.path)) {
console.log('Could not find chromedriver in default path:', chromedriver.path);
console.log('Falling back to use global chromedriver bin');
}