Chrome DevTools for coding agents
fix: improve error messages around --auto-connect (#1075)
Alex Rudenkobcb852dd2e44
diff --git a/README.md b/README.mdindex 31e9e9ba..88c31fe8 100644--- a/README.md+++ b/README.md@@ -459,7 +459,7 @@ The Chrome DevTools MCP server supports the following configuration option:<!-- BEGIN AUTO GENERATED OPTIONS -->- **`--autoConnect`/ `--auto-connect`**- If specified, automatically connects to a browser (Chrome 144+) running in the user data directory identified by the channel param. Requires the remoted debugging server to be started in the Chrome instance via chrome://inspect/#remote-debugging.+ If specified, automatically connects to a browser (Chrome 144+) running locally from the user data directory identified by the channel param (default channel is stable). Requires the remoted debugging server to be started in the Chrome instance via chrome://inspect/#remote-debugging.- **Type:** boolean- **Default:** `false`diff --git a/src/browser.ts b/src/browser.tsindex 3fb79a05..1b8cc164 100644--- a/src/browser.ts+++ b/src/browser.ts@@ -63,6 +63,7 @@ export async function ensureBrowserConnected(options: {handleDevToolsAsPage: true,};+ let autoConnect = false;if (options.wsEndpoint) {connectOptions.browserWSEndpoint = options.wsEndpoint;if (options.wsHeaders) {@@ -73,6 +74,7 @@ export async function ensureBrowserConnected(options: {} else if (channel || options.userDataDir) {const userDataDir = options.userDataDir;if (userDataDir) {+ autoConnect = true;// TODO: re-expose this logic via Puppeteer.const portPath = path.join(userDataDir, 'DevToolsActivePort');try {@@ -96,7 +98,7 @@ export async function ensureBrowserConnected(options: {connectOptions.browserWSEndpoint = browserWSEndpoint;} catch (error) {throw new Error(- `Could not connect to Chrome in ${userDataDir}. Check if Chrome is running and remote debugging is enabled.`,+ `Could not connect to Chrome in ${userDataDir}. Check if Chrome is running and remote debugging is enabled by going to chrome://inspect/#remote-debugging.`,{cause: error,},@@ -121,7 +123,7 @@ export async function ensureBrowserConnected(options: {browser = await puppeteer.connect(connectOptions);} catch (err) {throw new Error(- 'Could not connect to Chrome. Check if Chrome is running and remote debugging is enabled by going to chrome://inspect/#remote-debugging.',+ `Could not connect to Chrome. ${autoConnect ? `Check if Chrome is running and remote debugging is enabled by going to chrome://inspect/#remote-debugging.` : `Check if Chrome is running.`}`,{cause: err,},diff --git a/src/cli.ts b/src/cli.tsindex 1b3c585a..23f794fd 100644--- a/src/cli.ts+++ b/src/cli.ts@@ -11,7 +11,7 @@ export const cliOptions = {autoConnect: {type: 'boolean',description:- 'If specified, automatically connects to a browser (Chrome 144+) running in the user data directory identified by the channel param. Requires the remoted debugging server to be started in the Chrome instance via chrome://inspect/#remote-debugging.',+ 'If specified, automatically connects to a browser (Chrome 144+) running locally from the user data directory identified by the channel param (default channel is stable). Requires the remoted debugging server to be started in the Chrome instance via chrome://inspect/#remote-debugging.',conflicts: ['isolated', 'executablePath'],default: false,coerce: (value: boolean | undefined) => {