豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 73e1e24

Browse files
authored
fix(cli): avoid defaulting to isolated when userDataDir is provided (#1258)
## Summary Fix `chrome-devtools start` so it no longer implicitly enables `isolated` when `--userDataDir` is provided. Previously, the CLI wrapper always defaulted `isolated` to `true` for `start`, which caused `userDataDir` and `isolated` to conflict even when the user only specified `--userDataDir`. This made it impossible to start the CLI daemon against a persistent browser profile. ## Changes - Update `chrome-devtools start` default handling in `src/bin/chrome-devtools.ts` - only default `isolated=true` when `userDataDir` is not set - Clarify the `isolated` CLI description to document the conditional default - Update `docs/cli.md` to reflect that: - `headless` is enabled by default - `isolated` is enabled by default unless `--userDataDir` is provided - Fix a small error message typo ## Why This matches the intended semantics of the flags: - `--isolated` means use a temporary user data dir - `--userDataDir` means use a persistent, explicit user data dir If the user passes `--userDataDir`, the CLI should not also implicitly enable `isolated`. ## Testing - Ran: - `npm test -- tests/cli.test.ts` - `npm test -- tests/e2e/chrome-devtools.test.ts` Added an e2e regression test in `tests/e2e/chrome-devtools.test.ts` to verify that: - `chrome-devtools start --userDataDir <temp dir>` succeeds - the CLI no longer fails with `Arguments userDataDir and isolated are mutually exclusive` - the daemon starts successfully when `userDataDir` is provided
1 parent 4637ab9 commit 73e1e24

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

docs/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The CLI acts as a client to a background `chrome-devtools-mcp` daemon (uses Unix
1717

1818
- **Automatic Start**: The first time you call a tool (e.g., `list_pages`), the CLI automatically starts the MCP server and the browser in the background if they aren't already running.
1919
- **Persistence**: The same background instance is reused for subsequent commands, preserving the browser state (open pages, cookies, etc.).
20-
- **Manual Control**: You can explicitly manage the background process using `start`, `stop`, and `status`. The `start` command forwards all subsequent arguments to the underlying MCP server (e.g., `--headless`, `--userDataDir`) but not all args are supported. Run `chrome-devtools start --help` for supported args. Headless and isolated are enabled by default.
20+
- **Manual Control**: You can explicitly manage the background process using `start`, `stop`, and `status`. The `start` command forwards all subsequent arguments to the underlying MCP server (e.g., `--headless`, `--userDataDir`) but not all args are supported. Run `chrome-devtools start --help` for supported args. Headless is enabled by default. Isolated is enabled by default unless `--userDataDir` is provided.
2121

2222
```sh
2323
# Check if the daemon is running

src/bin/chrome-devtools.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ if (!('default' in cliOptions.headless)) {
5959
throw new Error('headless cli option unexpectedly does not have a default');
6060
}
6161
if ('default' in cliOptions.isolated) {
62-
throw new Error('headless cli option unexpectedly does not have a default');
62+
throw new Error('isolated cli option unexpectedly has a default');
6363
}
6464
startCliOptions.headless!.default = true;
65+
startCliOptions.isolated!.description =
66+
'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed. Defaults to true unless userDataDir is provided.';
6567

6668
const y = yargs(hideBin(process.argv))
6769
.scriptName('chrome-devtools')
@@ -92,7 +94,7 @@ y.command(
9294
await stopDaemon();
9395
}
9496
// Defaults but we do not want to affect the yargs conflict resolution.
95-
if (argv.isolated === undefined) {
97+
if (argv.isolated === undefined && argv.userDataDir === undefined) {
9698
argv.isolated = true;
9799
}
98100
if (argv.headless === undefined) {

tests/e2e/chrome-devtools.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
import assert from 'node:assert';
88
import {spawn} from 'node:child_process';
9+
import fs from 'node:fs';
10+
import os from 'node:os';
911
import path from 'node:path';
1012
import {describe, it, afterEach, beforeEach} from 'node:test';
1113

@@ -93,6 +95,29 @@ describe('chrome-devtools', () => {
9395
await assertDaemonIsNotRunning();
9496
});
9597

98+
it('can start the daemon with userDataDir', async () => {
99+
const userDataDir = path.join(
100+
os.tmpdir(),
101+
`chrome-devtools-test-${crypto.randomUUID()}`,
102+
);
103+
fs.mkdirSync(userDataDir, {recursive: true});
104+
105+
const startResult = await runCli(['start', '--userDataDir', userDataDir]);
106+
assert.strictEqual(
107+
startResult.status,
108+
0,
109+
`start command failed: ${startResult.stderr}`,
110+
);
111+
assert.ok(
112+
!startResult.stderr.includes(
113+
'Arguments userDataDir and isolated are mutually exclusive',
114+
),
115+
`unexpected conflict error: ${startResult.stderr}`,
116+
);
117+
118+
await assertDaemonIsRunning();
119+
});
120+
96121
it('can invoke list_pages', async () => {
97122
await assertDaemonIsNotRunning();
98123

0 commit comments

Comments
 (0)