Skip to main content

Configuration

Headed and headless mode

The CLI runs headless by default. To see the browser:

playwright-cli open https://playwright.dev --headed

Browser selection

playwright-cli open --browser=chrome # Google Chrome (default)
playwright-cli open --browser=firefox # Mozilla Firefox
playwright-cli open --browser=webkit # WebKit (Safari engine)
playwright-cli open --browser=msedge # Microsoft Edge

Device emulation

# Emulate a generic mobile device: Pixel 10 for Chromium, iPhone 17 for WebKit
playwright-cli open --mobile

# Emulate a named device from the Playwright device registry
playwright-cli open --device="iPhone 15"

--mobile is worth reaching for by default when a mobile layout is acceptable: mobile pages are usually lighter, so their snapshots are smaller and cheaper.

Profile modes

In-memory (default)

Cookies and storage persist between commands but are lost when the browser closes:

playwright-cli open https://example.com

Persistent

Profile saved to disk, survives browser restarts:

playwright-cli open https://example.com --persistent

Custom profile directory

playwright-cli open https://example.com --profile=./my-profile

Isolated

Explicit in-memory mode — equivalent to the default but can be set in the config file:

{
"browser": { "isolated": true }
}

Configuration file

For advanced settings, use a config file:

playwright-cli open example.com --config=path/to/config.json

Configuration is merged from four sources, each overriding the previous one:

  1. ~/.playwright/cli.config.json — global defaults for every workspace
  2. .playwright/cli.config.json in the workspace — loaded automatically when present, overridden with explicit --config
  3. PLAYWRIGHT_MCP_* environment variables
  4. Command-line options such as --browser, --headed, --device, --profile

Full config schema

{
browser?: {
browserName?: 'chromium' | 'firefox' | 'webkit';
isolated?: boolean; // keep the profile in memory
userDataDir?: string;
launchOptions?: {
channel?: string; // 'chrome', 'msedge', ...
headless?: boolean;
executablePath?: string;
args?: string[];
chromiumSandbox?: boolean;
slowMo?: number;
timeout?: number;
proxy?: {
server: string; // e.g., "http://myproxy:3128"
bypass?: string; // e.g., ".com,chromium.org"
username?: string;
password?: string;
};
};
contextOptions?: {
viewport?: { width: number; height: number };
locale?: string;
timezoneId?: string;
userAgent?: string;
colorScheme?: 'light' | 'dark' | 'no-preference';
storageState?: string;
permissions?: string[]; // e.g., ['geolocation', 'clipboard-read']
ignoreHTTPSErrors?: boolean;
serviceWorkers?: 'allow' | 'block';
};
cdpEndpoint?: string;
cdpHeaders?: Record<string, string>;
cdpTimeout?: number; // defaults to 30000, 0 disables
remoteEndpoint?: string | { endpoint: string, headers?, slowMo?, timeout? };
initPage?: string[]; // TypeScript files for page setup
initScript?: string[]; // JavaScript files for page init
};
extension?: boolean;
server?: {
port?: number;
host?: string;
allowedHosts?: string[];
};
capabilities?: string[]; // MCP tool capabilities; the CLI enables all of them
saveSession?: boolean;
sharedBrowserContext?: boolean;
outputDir?: string;
outputMaxSize?: number; // eviction threshold for output files, in bytes
console?: { level?: 'error' | 'warning' | 'info' | 'debug' };
network?: {
allowedOrigins?: string[]; // e.g., ["https://api.example.com", "http://localhost:*"]
blockedOrigins?: string[];
};
secrets?: Record<string, string>;
testIdAttribute?: string; // default: "data-testid"
timeouts?: {
action?: number; // default: 5000ms
navigation?: number; // default: 60000ms
expect?: number; // default: 5000ms
settle?: number; // default: 500ms
};
imageResponses?: 'allow' | 'omit';
snapshot?: {
mode?: 'full' | 'none';
boxes?: boolean; // include [box=x,y,width,height] in snapshots
};
allowUnrestrictedFileAccess?: boolean;
codegen?: 'typescript' | 'python' | 'java' | 'csharp' | 'none';
}

Example configs

Local development:

{
"browser": {
"launchOptions": { "headless": false }
}
}

CI environment:

{
"browser": {
"launchOptions": { "headless": true },
"contextOptions": { "viewport": { "width": 1280, "height": 720 } }
},
"outputDir": "./test-output"
}

Behind a proxy:

{
"browser": {
"launchOptions": {
"proxy": {
"server": "http://proxy.corp.example.com:8080",
"bypass": "localhost,*.internal.com"
}
}
}
}

Device emulation:

{
"browser": {
"contextOptions": {
"viewport": { "width": 375, "height": 812 },
"userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X)..."
}
}
}

Init scripts:

{
"browser": {
"initScript": ["./setup.js"],
"initPage": ["./setup-page.ts"]
}
}

See the final config after merging CLI options, environment variables, and config files:

playwright-cli config-print

Browser extension

Connect to your existing browser tabs instead of launching a new browser:

playwright-cli attach --extension

See Attach for details.

Environment variables

VariableDescription
PLAYWRIGHT_CLI_SESSIONDefault session name
PLAYWRIGHT_MCP_ALLOWED_HOSTSAllowed hosts for the server (comma-separated)
PLAYWRIGHT_MCP_ALLOWED_ORIGINSOrigins the browser may request (semicolon-separated)
PLAYWRIGHT_MCP_ALLOW_UNRESTRICTED_FILE_ACCESSAllow file access outside the workspace
PLAYWRIGHT_MCP_BLOCKED_ORIGINSOrigins to block (semicolon-separated)
PLAYWRIGHT_MCP_BLOCK_SERVICE_WORKERSBlock service workers
PLAYWRIGHT_MCP_BROWSERBrowser to use (chrome, firefox, webkit, msedge, ...)
PLAYWRIGHT_MCP_CAPSEnable capabilities (comma-separated)
PLAYWRIGHT_MCP_CDP_ENDPOINTCDP endpoint
PLAYWRIGHT_MCP_CDP_HEADERSHeaders to send with the CDP connect request
PLAYWRIGHT_MCP_CDP_TIMEOUTCDP connect timeout (ms)
PLAYWRIGHT_MCP_CODEGENCode generation language
PLAYWRIGHT_MCP_CONFIGConfig file path
PLAYWRIGHT_MCP_CONSOLE_LEVELConsole message level
PLAYWRIGHT_MCP_DEVICEDevice to emulate
PLAYWRIGHT_MCP_EXECUTABLE_PATHCustom browser executable
PLAYWRIGHT_MCP_EXTENSIONConnect via browser extension
PLAYWRIGHT_MCP_GRANT_PERMISSIONSBrowser permissions (comma-separated)
PLAYWRIGHT_MCP_HEADLESSRun headless
PLAYWRIGHT_MCP_HOSTHost to bind the server to
PLAYWRIGHT_MCP_IGNORE_HTTPS_ERRORSIgnore HTTPS errors
PLAYWRIGHT_MCP_IMAGE_RESPONSESallow or omit
PLAYWRIGHT_MCP_INIT_PAGEPage init TypeScript
PLAYWRIGHT_MCP_INIT_SCRIPTPage init JavaScript
PLAYWRIGHT_MCP_ISOLATEDIn-memory profile
PLAYWRIGHT_MCP_MOBILEEmulate a generic mobile device
PLAYWRIGHT_MCP_OUTPUT_DIROutput directory
PLAYWRIGHT_MCP_OUTPUT_MAX_SIZEOutput eviction threshold (bytes)
PLAYWRIGHT_MCP_PORTServer port
PLAYWRIGHT_MCP_PROFILE_DIR_NAMEProfile directory name for extension mode
PLAYWRIGHT_MCP_PROXY_BYPASSDomains to bypass proxy
PLAYWRIGHT_MCP_PROXY_SERVERProxy server URL
PLAYWRIGHT_MCP_REMOTE_HEADERSHeaders for the remote endpoint connect request
PLAYWRIGHT_MCP_SANDBOXEnable or disable the Chromium sandbox
PLAYWRIGHT_MCP_SECRETS_FILESecrets file (dotenv)
PLAYWRIGHT_MCP_STORAGE_STATEStorage state file
PLAYWRIGHT_MCP_TEST_ID_ATTRIBUTETest ID attribute
PLAYWRIGHT_MCP_TIMEOUT_ACTIONAction timeout (ms)
PLAYWRIGHT_MCP_TIMEOUT_NAVIGATIONNavigation timeout (ms)
PLAYWRIGHT_MCP_TIMEOUT_SETTLEPost-action settle timeout (ms)
PLAYWRIGHT_MCP_USER_AGENTCustom user agent
PLAYWRIGHT_MCP_USER_DATA_DIRProfile directory
PLAYWRIGHT_MCP_VIEWPORT_SIZEViewport size (e.g., "1280x720")

All open and attach parameters

playwright-cli open [url] # open browser
playwright-cli open --headed # show browser window
playwright-cli open --browser=firefox # specific browser
playwright-cli open --mobile # generic mobile device
playwright-cli open --device="iPhone 15" # named device
playwright-cli open --persistent # persist profile to disk
playwright-cli open --profile=<path> # custom profile directory
playwright-cli open --config=file.json # use config file

playwright-cli attach [name] # attach to a bound browser by name
playwright-cli attach --extension # connect via extension
playwright-cli attach --cdp=chrome # connect to a running channel
playwright-cli attach --cdp=<url> # connect via CDP endpoint
playwright-cli attach --endpoint=<url> # connect to a Playwright server
playwright-cli attach --config=file.json # use config file