Skip to content

Chrome DevTools for coding agents

feat: support --user-data-dir (#622)

Alex Rudenkofcaf55354c2a
diff --git a/README.md b/README.md
index ab5db6ab..5864b073 100644
--- a/README.md
+++ b/README.md
@@ -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.
diff --git a/src/cli.ts b/src/cli.ts
index 5ce8673e..15808537 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -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',
@@ -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
diff --git a/src/main.ts b/src/main.ts
index 1b7111fd..f0092f33 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -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,
diff --git a/tests/cli.test.ts b/tests/cli.test.ts
index c5c8b088..df0835c1 100644
--- a/tests/cli.test.ts
+++ b/tests/cli.test.ts
@@ -25,7 +25,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
- isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
});
@@ -42,7 +41,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
- isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
'browser-url': 'http://localhost:3000',
browserUrl: 'http://localhost:3000',
@@ -50,6 +48,24 @@ describe('cli args parsing', () => {
});
});
+ 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',
@@ -61,7 +77,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
- isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
'browser-url': undefined,
browserUrl: undefined,
@@ -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',
@@ -100,7 +114,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
- isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
viewport: {
@@ -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'],
@@ -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',
@@ -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',
@@ -192,7 +202,6 @@ describe('cli args parsing', () => {
...defaultArgs,
_: [],
headless: false,
- isolated: false,
$0: 'npx chrome-devtools-mcp@latest',
channel: 'stable',
'category-emulation': false,