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

Commit 9a1b705

Browse files
committed
fix(cli): avoid defaulting to isolated when userDataDir is provided
1 parent cea963b commit 9a1b705

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
@@ -57,9 +57,11 @@ if (!('default' in cliOptions.headless)) {
5757
throw new Error('headless cli option unexpectedly does not have a default');
5858
}
5959
if ('default' in cliOptions.isolated) {
60-
throw new Error('headless cli option unexpectedly does not have a default');
60+
throw new Error('isolated cli option unexpectedly has a default');
6161
}
6262
startCliOptions.headless!.default = true;
63+
startCliOptions.isolated!.description =
64+
'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.';
6365

6466
const y = yargs(hideBin(process.argv))
6567
.scriptName('chrome-devtools')
@@ -90,7 +92,7 @@ y.command(
9092
await stopDaemon();
9193
}
9294
// Defaults but we do not want to affect the yargs conflict resolution.
93-
if (argv.isolated === undefined) {
95+
if (argv.isolated === undefined && argv.userDataDir === undefined) {
9496
argv.isolated = true;
9597
}
9698
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)