Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,12 @@ The Chrome DevTools MCP server supports the following configuration option:
- **Type:** string

- **`--isolated`**
If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed.
If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to false.
- **Type:** boolean
- **Default:** `false`

- **`--userDataDir`**
Path to the user data directory for Chrome. Default is $HOME/.cache/chrome-devtools-mcp/chrome-profile$CHANNEL_SUFFIX_IF_NON_STABLE
- **Type:** string

- **`--channel`**
Specify a different Chrome channel that should be used. The default is the stable channel version.
Expand Down
13 changes: 11 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ export const cliOptions = {
isolated: {
type: 'boolean',
description:
'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed.',
default: false,
'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to false.',
},
userDataDir: {
type: 'string',
description:
'Path to the user data directory for Chrome. Default is $HOME/.cache/chrome-devtools-mcp/chrome-profile$CHANNEL_SUFFIX_IF_NON_STABLE',
conflicts: ['browserUrl', 'wsEndpoint', 'isolated'],
},
channel: {
type: 'string',
Expand Down Expand Up @@ -212,6 +217,10 @@ export function parseArguments(version: string, argv = process.argv) {
'Disable tools in the performance category',
],
['$0 --no-category-network', 'Disable tools in the network category'],
[
'$0 --user-data-dir=/tmp/user-data-dir',
'Use a custom user data directory',
],
]);

return yargsInstance
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ async function getContext(): Promise<McpContext> {
headless: args.headless,
executablePath: args.executablePath,
channel: args.channel as Channel,
isolated: args.isolated,
isolated: args.isolated ?? false,
userDataDir: args.userDataDir,
logFile,
viewport: args.viewport,
args: extraArgs,
Expand Down
27 changes: 18 additions & 9 deletions tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
});
Expand All @@ -42,14 +41,31 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
'browser-url': 'http://localhost:3000',
browserUrl: 'http://localhost:3000',
u: 'http://localhost:3000',
});
});

it('parses with user data dir', async () => {
const args = parseArguments('1.0.0', [
'node',
'main.js',
'--user-data-dir',
'/tmp/chrome-profile',
]);
assert.deepStrictEqual(args, {
...defaultArgs,
_: [],
headless: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
'user-data-dir': '/tmp/chrome-profile',
userDataDir: '/tmp/chrome-profile',
});
});

it('parses an empty browser url', async () => {
const args = parseArguments('1.0.0', [
'node',
Expand All @@ -61,7 +77,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
'browser-url': undefined,
browserUrl: undefined,
Expand All @@ -81,7 +96,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
'executable-path': '/tmp/test 123/chrome',
e: '/tmp/test 123/chrome',
Expand All @@ -100,7 +114,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
viewport: {
Expand All @@ -121,7 +134,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
'chrome-arg': ['--no-sandbox', '--disable-setuid-sandbox'],
Expand All @@ -140,7 +152,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
'ws-endpoint': 'ws://127.0.0.1:9222/devtools/browser/abc123',
wsEndpoint: 'ws://127.0.0.1:9222/devtools/browser/abc123',
Expand All @@ -159,7 +170,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
'ws-endpoint': 'wss://example.com:9222/devtools/browser/abc123',
wsEndpoint: 'wss://example.com:9222/devtools/browser/abc123',
Expand Down Expand Up @@ -192,7 +202,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
'category-emulation': false,
Expand Down