Direct execution of ChromeDriver binary through the provided CLI wrapper, enabling command-line usage and integration with shell scripts and CI/CD pipelines.
Execute ChromeDriver directly from the command line with full argument support.
# Direct execution with arguments
chromedriver [arguments]
# Common usage patterns
chromedriver --port=9515
chromedriver --port=9516 --verbose
chromedriver --log-path=./chromedriver.log --log-level=DEBUGUsage Examples:
# Basic ChromeDriver startup
chromedriver
# Start on custom port
chromedriver --port=9516
# Verbose logging
chromedriver --verbose
# Custom log file and level
chromedriver --log-path=./logs/chromedriver.log --log-level=INFO
# Multiple options
chromedriver --port=9515 --verbose --log-path=./chromedriver.logChromeDriver is automatically added to the NPM binary path, making it available as a command.
# Available in node_modules/.bin/
./node_modules/.bin/chromedriver [arguments]
# Via NPM scripts
npm run chromedriver -- [arguments]
# Direct execution if globally installed
chromedriver [arguments]NPM Script Integration:
{
"scripts": {
"start-chromedriver": "chromedriver --port=9515",
"chromedriver-verbose": "chromedriver --verbose --log-path=./logs/chromedriver.log",
"test-setup": "chromedriver --port=9516 &",
"test": "npm run test-setup && jest && pkill chromedriver"
}
}The CLI wrapper handles process lifecycle and signal management.
# Process management
chromedriver & # Run in background
kill -TERM $! # Graceful shutdown
# Signal handling
SIGTERM → Graceful shutdown
SIGINT → Immediate terminationUsage Examples:
# Background execution
chromedriver --port=9515 &
CHROMEDRIVER_PID=$!
# Run tests
npm test
# Clean shutdown
kill -TERM $CHROMEDRIVER_PID
wait $CHROMEDRIVER_PIDThe CLI wrapper (bin/chromedriver) performs these operations:
/**
* CLI wrapper functionality
* 1. Resolves binary path from the package
* 2. Spawns ChromeDriver process with passed arguments
* 3. Pipes stdout/stderr to parent process
* 4. Handles process termination signals
*/
// Process argument passing
const args = process.argv.slice(2);
const binPath = require(path.join(__dirname, "..", "lib", "chromedriver")).path;
const cp = spawn(binPath, args);
// Stream handling
cp.stdout.pipe(process.stdout);
cp.stderr.pipe(process.stderr);
// Signal handling
process.on("SIGTERM", function() {
cp.kill("SIGTERM");
process.exit(1);
});The binary path is resolved through the main package module:
# Path resolution chain
bin/chromedriver → lib/chromedriver.js → platform-specific binary pathPlatform-Specific Paths:
lib/chromedriver/chromedriver.exelib/chromedriver/chromedriverchromedriver command# Port specification
chromedriver --port=9515 # Custom port
chromedriver --port=0 # Random available port# Logging options
chromedriver --verbose # Verbose output
chromedriver --log-path=./chromedriver.log # Log file
chromedriver --log-level=INFO # Log level
chromedriver --silent # Minimal output# Network binding
chromedriver --whitelisted-ips=127.0.0.1,192.168.1.0/24
chromedriver --allowed-origins=*
chromedriver --allowed-ips=127.0.0.1,192.168.1.100# Security configuration
chromedriver --disable-dev-shm-usage
chromedriver --no-sandbox
chromedriver --disable-extensions
chromedriver --disable-background-timer-throttling# GitHub Actions example
- name: Start ChromeDriver
run: |
chromedriver --port=9515 &
echo "CHROMEDRIVER_PID=$!" >> $GITHUB_ENV
- name: Run tests
run: npm test
- name: Stop ChromeDriver
run: kill $CHROMEDRIVER_PID
if: always()# GitLab CI example
test:
script:
- chromedriver --port=9515 &
- CHROMEDRIVER_PID=$!
- npm test
- kill $CHROMEDRIVER_PID# Dockerfile example
FROM node:18
# Install ChromeDriver package
RUN npm install -g chromedriver
# Set up ChromeDriver service
EXPOSE 9515
CMD ["chromedriver", "--port=9515", "--whitelisted-ips=0.0.0.0"]#!/bin/bash
# test-runner.sh
# Start ChromeDriver in background
chromedriver --port=9515 --log-path=./logs/chromedriver.log &
CHROMEDRIVER_PID=$!
# Wait for ChromeDriver to be ready
sleep 2
# Run tests
echo "Running tests with ChromeDriver PID: $CHROMEDRIVER_PID"
npm test
TEST_RESULT=$?
# Clean up
echo "Stopping ChromeDriver..."
kill -TERM $CHROMEDRIVER_PID
wait $CHROMEDRIVER_PID
exit $TEST_RESULTIf the ChromeDriver binary is missing:
Could not find chromedriver in default path: /path/to/binary
Falling back to use global chromedriver binThe wrapper automatically falls back to the system-installed ChromeDriver.
ChromeDriver will report port conflicts:
# Error output
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully on port 9515.On macOS, unsigned binaries may require permission:
# macOS permission dialog may appear
# Allow ChromeDriver to run in System Preferences → Security & PrivacyThe CLI wrapper is a simple pass-through script that doesn't process environment variables. All configuration is done through command-line arguments passed directly to the ChromeDriver binary:
# Configuration through command-line arguments only
chromedriver --port=9515 --verbose --log-path=./test.log