Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ The Chrome DevTools MCP server supports the following configuration option:
- **Type:** boolean
- **Default:** `true`

- **`--profileDirectory`/ `--profile-directory`, `-profile-dir`**
Specify which Chrome profile to use by its directory name (e.g., "Profile 1", "Default"). Only works with --autoConnect or when launching Chrome.
- **Type:** string

<!-- END AUTO GENERATED OPTIONS -->

Pass them via the `args` property in the JSON configuration. For example:
Expand Down
4 changes: 4 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ interface McpLaunchOptions {
};
args?: string[];
devtools: boolean;
profileDirectory?: string;
}

export async function launch(options: McpLaunchOptions): Promise<Browser> {
Expand All @@ -170,6 +171,9 @@ export async function launch(options: McpLaunchOptions): Promise<Browser> {
...(options.args ?? []),
'--hide-crash-restore-bubble',
];
if (options.profileDirectory) {
args.push(`--profile-directory=${options.profileDirectory}`);
}
if (headless) {
args.push('--screen-info={3840x2160}');
}
Expand Down
15 changes: 15 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ export const cliOptions = {
default: true,
describe: 'Set to false to exclude tools related to network.',
},
profileDirectory: {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably should be using https://pptr.dev/api/puppeteer.browser.browsercontexts to locate the browser context for the profile (currently the default browser context is used)

type: 'string',
description:
'Specify which Chrome profile to use by its directory name (e.g., "Profile 1", "Default"). Only works with --autoConnect or when launching Chrome.',
Comment thread
Yasindu20 marked this conversation as resolved.
Outdated
alias: 'profile-dir',
conflicts: ['browserUrl', 'wsEndpoint'],
},
} satisfies Record<string, YargsOptions>;

export function parseArguments(version: string, argv = process.argv) {
Expand Down Expand Up @@ -247,6 +254,14 @@ export function parseArguments(version: string, argv = process.argv) {
'$0 --auto-connect --channel=canary',
'Connect to a canary Chrome instance (Chrome 145+) running instead of launching a new instance',
],
[
'$0 --auto-connect --profile-directory="Profile 1"',
'Connect to Chrome using a specific profile (requires Chrome 145+)',
],
[
'$0 --channel=stable --profile-directory="Work Profile"',
'Launch stable Chrome with a specific profile',
],
]);

return yargsInstance
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async function getContext(): Promise<McpContext> {
args: extraArgs,
acceptInsecureCerts: args.acceptInsecureCerts,
devtools,
profileDirectory: args.profileDirectory,
});

if (context?.browser !== browser) {
Expand Down