Skip to content

fix(browser): suggest custom profiles for missing port files - #3496

Open
AmarGhugare wants to merge 1 commit into
ChromeDevTools:mainfrom
AmarGhugare:fix/autoconnect-profile-hint
Open

AmarGhugare wants to merge 1 commit into
ChromeDevTools:mainfrom
AmarGhugare:fix/autoconnect-profile-hint

Conversation

@AmarGhugare

Copy link
Copy Markdown
Contributor

Fixes #889.

When channel-based auto-connect cannot find the default profile's DevToolsActivePort file, suggest --user-data-dir for a custom profile. Keep the existing running-browser/remote-debugging guidance and the original error cause.

Only add the hint for a missing-file (ENOENT) cause. Puppeteer uses the same outer message for malformed port files and refused connections, where changing the profile would be misleading. Permission failures also keep their existing behavior; those are covered separately by #3487. The README guidance for #889 was already updated in #3386.

Validation on Windows, Node 24.19.0, Chrome 157.0.8103.78:

  • Updated missing-file regression fails before the fix; controls cover EPERM, EACCES, malformed files, and refused connections.
  • npm run test -- tests/browser.test.ts: 41 passed.
  • npm run format: passed.
  • npm run test: 1,985 passed, 5 skipped, zero failures.

@OrKoN

OrKoN commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

@nattallius could you please help with review of this fix?

@nattallius

Copy link
Copy Markdown
Contributor

Sure, i will

@nattallius nattallius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR. Please note that #3487, which is also open, changes the same error handling in BrowserManager. It adds devToolsActivePortPermissionError() to src/utils/errorHandling.ts to detect permission errors. Please follow the same approach here: move the ENOENT check into a helper in that file and add a unit test for it. Both PRs change the same catch block, so whichever one merges second will need to rebase and combine both changes.

Also, please change Fixes #889 to Refs #889 in the description. This PR improves the error message, but the docs for using --autoConnect with --userDataDir are still missing, so the issue should stay open.

Comment thread src/BrowserManager.ts
Comment on lines +485 to +486
' If Chrome uses a custom profile directory, ' +
'pass --user-data-dir with that directory.';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

--user-data-dir is also a Chrome switch, and docs/advanced-usage.md tells users to start Chrome with it. A user can read this hint as "restart Chrome with --user-data-dir", which doesn't fix the connection. Please name the MCP option, for example:

' If the browser uses a non-default profile directory (for example, ' +
'Chromium), pass --userDataDir=<profile dir> to chrome-devtools-mcp.'

Comment thread src/BrowserManager.ts
'by going to chrome://inspect/#remote-debugging.'
: 'Check if Chrome is running.';
if (
connectOptions.channel &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

connectOptions.channel isn't needed: Puppeteer only throws Could not find DevToolsActivePort from its channel path, and the userDataDir path throws its own error before puppeteer.connect is called.

Comment thread src/BrowserManager.ts
connectOptions.channel &&
err instanceof Error &&
err.message.startsWith('Could not find DevToolsActivePort for ') &&
typeof err.cause === 'object' &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The typeof / null / 'code' in checks only exist to narrow err.cause for TypeScript. Please replace them with one type guard in src/utils/errorHandling.ts, so this check and isErrnoPermissionError() from #3487 can share it. For example:

function hasErrnoCode(error: unknown, ...codes: string[]): boolean {
  return (
    error instanceof Error &&
    'code' in error &&
    typeof error.code === 'string' &&
    codes.includes(error.code)
  );
}

Then this check becomes hasErrnoCode(err.cause, 'ENOENT').

Comment thread tests/browser.test.ts

for (const {name, message, cause} of [
{
name: 'a permission error (EPERM)',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove the EPERM and EACCES cases. #3487 covers this path. The malformed-file and ECONNREFUSED cases are the useful ones: they have the same outer message as ENOENT, which shows why the code check is needed.

Comment thread tests/browser.test.ts

await assert.rejects(manager.ensureBrowser(), error => {
assert.ok(error instanceof Error);
assert.doesNotMatch(error.message, /--user-data-dir/);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please compare the full message with assert.strictEqual instead. If the hint wording changes, this regex no longer matches, and these tests keep passing even if the hint appears in the wrong case.

assert.strictEqual(
  error.message,
  'Could not connect to Chrome. Check if Chrome is running and remote ' +
    'debugging is enabled by going to chrome://inspect/#remote-debugging.',
);

@OrKoN
OrKoN removed their request for review November 23, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The DevTools MCP is hardcoded to look for Chrome in standard locations

3 participants