Skip to content

Commit 320e974

Browse files
committed
feat: add --profile-directory option to specify Chrome profile
Added a new CLI option to allow users to specify which Chrome profile to use when launching the browser. Changes: - Added --profile-directory CLI argument - Updated BrowserOptions interface - Connected CLI arg to Chrome launch flag - Added documentation in README.md
1 parent a94dc0e commit 320e974

4 files changed

Lines changed: 24 additions & 0 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ The Chrome DevTools MCP server supports the following configuration option:
443443
- **Type:** boolean
444444
- **Default:** `true`
445445

446+
- **`--profileDirectory`/ `--profile-directory`, `-profile-dir`**
447+
Specify which Chrome profile to use by its directory name (e.g., "Profile 1", "Default"). Only works with --autoConnect or when launching Chrome.
448+
- **Type:** string
449+
446450
<!-- END AUTO GENERATED OPTIONS -->
447451

448452
Pass them via the `args` property in the JSON configuration. For example:

src/browser.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ interface McpLaunchOptions {
144144
};
145145
args?: string[];
146146
devtools: boolean;
147+
profileDirectory?: string;
147148
}
148149

149150
export async function launch(options: McpLaunchOptions): Promise<Browser> {
@@ -170,6 +171,9 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
170171
...(options.args ?? []),
171172
'--hide-crash-restore-bubble',
172173
];
174+
if (options.profileDirectory) {
175+
args.push(`--profile-directory=${options.profileDirectory}`);
176+
}
173177
if (headless) {
174178
args.push('--screen-info={3840x2160}');
175179
}

src/cli.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ export const cliOptions = {
183183
default: true,
184184
describe: 'Set to false to exclude tools related to network.',
185185
},
186+
profileDirectory: {
187+
type: 'string',
188+
description:
189+
'Specify which Chrome profile to use by its directory name (e.g., "Profile 1", "Default"). Only works with --autoConnect or when launching Chrome.',
190+
alias: 'profile-dir',
191+
conflicts: ['browserUrl', 'wsEndpoint'],
192+
},
186193
} satisfies Record<string, YargsOptions>;
187194

188195
export function parseArguments(version: string, argv = process.argv) {
@@ -247,6 +254,14 @@ export function parseArguments(version: string, argv = process.argv) {
247254
'$0 --auto-connect --channel=canary',
248255
'Connect to a canary Chrome instance (Chrome 145+) running instead of launching a new instance',
249256
],
257+
[
258+
'$0 --auto-connect --profile-directory="Profile 1"',
259+
'Connect to Chrome using a specific profile (requires Chrome 145+)',
260+
],
261+
[
262+
'$0 --channel=stable --profile-directory="Work Profile"',
263+
'Launch stable Chrome with a specific profile',
264+
],
250265
]);
251266

252267
return yargsInstance

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ async function getContext(): Promise<McpContext> {
8181
args: extraArgs,
8282
acceptInsecureCerts: args.acceptInsecureCerts,
8383
devtools,
84+
profileDirectory: args.profileDirectory,
8485
});
8586

8687
if (context?.browser !== browser) {

0 commit comments

Comments
 (0)