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

Commit bcb852d

Browse files
authored
fix: improve error messages around --auto-connect (#1075)
1 parent 2216b3a commit bcb852d

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ The Chrome DevTools MCP server supports the following configuration option:
459459
<!-- BEGIN AUTO GENERATED OPTIONS -->
460460

461461
- **`--autoConnect`/ `--auto-connect`**
462-
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.
462+
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.
463463
- **Type:** boolean
464464
- **Default:** `false`
465465

src/browser.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export async function ensureBrowserConnected(options: {
6363
handleDevToolsAsPage: true,
6464
};
6565

66+
let autoConnect = false;
6667
if (options.wsEndpoint) {
6768
connectOptions.browserWSEndpoint = options.wsEndpoint;
6869
if (options.wsHeaders) {
@@ -73,6 +74,7 @@ export async function ensureBrowserConnected(options: {
7374
} else if (channel || options.userDataDir) {
7475
const userDataDir = options.userDataDir;
7576
if (userDataDir) {
77+
autoConnect = true;
7678
// TODO: re-expose this logic via Puppeteer.
7779
const portPath = path.join(userDataDir, 'DevToolsActivePort');
7880
try {
@@ -96,7 +98,7 @@ export async function ensureBrowserConnected(options: {
9698
connectOptions.browserWSEndpoint = browserWSEndpoint;
9799
} catch (error) {
98100
throw new Error(
99-
`Could not connect to Chrome in ${userDataDir}. Check if Chrome is running and remote debugging is enabled.`,
101+
`Could not connect to Chrome in ${userDataDir}. Check if Chrome is running and remote debugging is enabled by going to chrome://inspect/#remote-debugging.`,
100102
{
101103
cause: error,
102104
},
@@ -121,7 +123,7 @@ export async function ensureBrowserConnected(options: {
121123
browser = await puppeteer.connect(connectOptions);
122124
} catch (err) {
123125
throw new Error(
124-
'Could not connect to Chrome. Check if Chrome is running and remote debugging is enabled by going to chrome://inspect/#remote-debugging.',
126+
`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.`}`,
125127
{
126128
cause: err,
127129
},

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const cliOptions = {
1111
autoConnect: {
1212
type: 'boolean',
1313
description:
14-
'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.',
14+
'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.',
1515
conflicts: ['isolated', 'executablePath'],
1616
default: false,
1717
coerce: (value: boolean | undefined) => {

0 commit comments

Comments
 (0)