-
Notifications
You must be signed in to change notification settings - Fork 993
fix: do not set channel if executablePath is provided #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import yargs from 'yargs'; | ||
| import {hideBin} from 'yargs/helpers'; | ||
|
|
||
| export const cliOptions = { | ||
| browserUrl: { | ||
| type: 'string' as const, | ||
| description: | ||
| 'Connect to a running Chrome instance using port forwarding. For more details see: https://developer.chrome.com/docs/devtools/remote-debugging/local-server.', | ||
| alias: 'u', | ||
| coerce: (url: string) => { | ||
| new URL(url); | ||
| return url; | ||
| }, | ||
| }, | ||
| headless: { | ||
| type: 'boolean' as const, | ||
| description: 'Whether to run in headless (no UI) mode.', | ||
| default: false, | ||
| }, | ||
| executablePath: { | ||
| type: 'string' as const, | ||
| description: 'Path to custom Chrome executable.', | ||
| conflicts: 'browserUrl', | ||
| alias: 'e', | ||
| }, | ||
| isolated: { | ||
| type: 'boolean' as const, | ||
| description: | ||
| 'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed.', | ||
| default: false, | ||
| }, | ||
| customDevtools: { | ||
| type: 'string' as const, | ||
| description: 'Path to custom DevTools.', | ||
| hidden: true, | ||
| conflicts: 'browserUrl', | ||
| alias: 'd', | ||
| }, | ||
| channel: { | ||
| type: 'string' as const, | ||
| description: | ||
| 'Specify a different Chrome channel that should be used. The default is the stable channel version.', | ||
| choices: ['stable', 'canary', 'beta', 'dev'] as const, | ||
| conflicts: ['browserUrl', 'executablePath'], | ||
| }, | ||
| logFile: { | ||
| type: 'string' as const, | ||
| describe: 'Save the logs to file.', | ||
| hidden: true, | ||
| }, | ||
| }; | ||
|
|
||
| export function parseArguments(version: string, argv = process.argv) { | ||
| const yargsInstance = yargs(hideBin(argv)) | ||
| .scriptName('npx chrome-devtools-mcp@latest') | ||
| .options(cliOptions) | ||
| .check(args => { | ||
| // We can't set default in the options else | ||
| // Yargs will complain | ||
| if (!args.channel && !args.browserUrl && !args.executablePath) { | ||
| args.channel = 'stable'; | ||
| } | ||
| return true; | ||
| }) | ||
| .example([ | ||
| [ | ||
| '$0 --browserUrl http://127.0.0.1:9222', | ||
| 'Connect to an existing browser instance', | ||
| ], | ||
| ['$0 --channel beta', 'Use Chrome Beta installed on this system'], | ||
| ['$0 --channel canary', 'Use Chrome Canary installed on this system'], | ||
| ['$0 --channel dev', 'Use Chrome Dev installed on this system'], | ||
| ['$0 --channel stable', 'Use stable Chrome installed on this system'], | ||
| ['$0 --logFile /tmp/log.txt', 'Save logs to a file'], | ||
| ['$0 --help', 'Print CLI options'], | ||
| ]); | ||
|
|
||
| return yargsInstance | ||
| .wrap(Math.min(120, yargsInstance.terminalWidth())) | ||
| .help() | ||
| .version(version) | ||
| .parseSync(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| import assert from 'node:assert'; | ||
| import {describe, it} from 'node:test'; | ||
|
|
||
| import {parseArguments} from '../src/cli.js'; | ||
|
|
||
| describe('cli args parsing', () => { | ||
| it('parses with default args', async () => { | ||
| const args = parseArguments('1.0.0', ['node', 'main.js']); | ||
| assert.deepStrictEqual(args, { | ||
| _: [], | ||
| headless: false, | ||
| isolated: false, | ||
| $0: 'npx chrome-devtools-mcp@latest', | ||
| channel: 'stable', | ||
| }); | ||
| }); | ||
|
|
||
| it('parses with browser url', async () => { | ||
| const args = parseArguments('1.0.0', [ | ||
| 'node', | ||
| 'main.js', | ||
| '--browserUrl', | ||
| 'http://localhost:3000', | ||
| ]); | ||
| assert.deepStrictEqual(args, { | ||
| _: [], | ||
| headless: false, | ||
| isolated: false, | ||
| $0: 'npx chrome-devtools-mcp@latest', | ||
| 'browser-url': 'http://localhost:3000', | ||
| browserUrl: 'http://localhost:3000', | ||
| u: 'http://localhost:3000', | ||
| }); | ||
| }); | ||
|
|
||
| it('parses with executable path', async () => { | ||
| const args = parseArguments('1.0.0', [ | ||
| 'node', | ||
| 'main.js', | ||
| '--executablePath', | ||
| '/tmp/test 123/chrome', | ||
| ]); | ||
| assert.deepStrictEqual(args, { | ||
| _: [], | ||
| headless: false, | ||
| isolated: false, | ||
| $0: 'npx chrome-devtools-mcp@latest', | ||
| 'executable-path': '/tmp/test 123/chrome', | ||
| e: '/tmp/test 123/chrome', | ||
| executablePath: '/tmp/test 123/chrome', | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.