Skip to content

[Bug]: connectOverCDP('chrome') ignores XDG_CONFIG_HOME / CHROME_CONFIG_HOME when locating DevToolsActivePort on Linux #43880

Closed

Description

@rickardof

Version

1.64.1 (latest). The relevant code is unchanged on main (df99ada).

Steps to reproduce

On Linux, chromium.connectOverCDP('chrome') (and chrome-beta, msedge, ...) finds the running browser by reading DevToolsActivePort from a hardcoded os.homedir()/.config/<product> directory. Chromium resolves its default user data dir from $CHROME_CONFIG_HOME, then $XDG_CONFIG_HOME, then ~/.config (docs/user_data_dir.md), so when either variable is set Chrome writes the file somewhere Playwright never looks.

Chrome 136+ refuses --remote-debugging-port on the default data dir, and $XDG_CONFIG_HOME/google-chrome counts as the default dir. To emulate "Chrome running with remote debugging enabled in its default dir" in a script, the repro below points Chrome at that directory through a symlink:

export XDG_CONFIG_HOME=/tmp/xdg
mkdir -p $XDG_CONFIG_HOME/real
ln -s $XDG_CONFIG_HOME/real $XDG_CONFIG_HOME/google-chrome   # the dir Chrome would use by default
google-chrome --headless=new --remote-debugging-port=0 --user-data-dir=$XDG_CONFIG_HOME/real about:blank &
cat $XDG_CONFIG_HOME/google-chrome/DevToolsActivePort        # Chrome did write it, here
// repro.js
const { chromium } = require('playwright-core');
(async () => {
  const browser = await chromium.connectOverCDP('chrome');
  console.log('connected, contexts:', browser.contexts().length);
  await browser.close();
})().catch(e => { console.error(e.message); process.exit(1); });
node repro.js

Expected behavior

Playwright looks for DevToolsActivePort in the same directory Chrome uses, so it honors CHROME_CONFIG_HOME and XDG_CONFIG_HOME the way Chrome does, and connects.

Actual behavior

browserType.connectOverCDP: Could not connect to chrome: DevToolsActivePort file not found at /home/<user>/.config/google-chrome/DevToolsActivePort.
Make sure chrome is running with remote debugging enabled. Navigate to

        chrome://inspect/#remote-debugging

and check "Allow remote debugging for this browser instance".

The hint is misleading here: remote debugging is enabled, and the file exists in the directory Chrome actually uses.

Additional context

The Linux user data dirs are hardcoded as path.join(os.homedir(), '.config', '<product>') in two tables that are kept in sync by hand:

  • packages/utils/chromiumChannels.ts (channelToDefaultUserDataDir), used by resolveChannelEndpoint in packages/playwright-core/src/server/chromium/chromium.ts and by the MCP extension context factory
  • packages/playwright-core/src/tools/cli-client/channelSessions.ts (channelToUserDataDir), used for playwright-cli attach

Proposed fix, applied to both tables:

// Chromium resolves the Linux config dir from $CHROME_CONFIG_HOME, then $XDG_CONFIG_HOME, then ~/.config.
const linuxConfigHome = process.env.CHROME_CONFIG_HOME || process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config');

// every 'linux' entry: path.join(os.homedir(), '.config', 'google-chrome')  ->  path.join(linuxConfigHome, 'google-chrome')

Reading the right file is not enough to make the repro above connect, because of a second, related problem in resolveChannelEndpoint: it only reads line 1 of DevToolsActivePort (the port) and always builds ws://localhost:${port}/devtools/browser. With the file found, Chrome in --remote-debugging-port mode answers that URL with 404 Not Found, because it expects the path from line 2 (/devtools/browser/<uuid>). Using line 2 when present, and keeping the current path as the fallback, fixes it:

const [portLine, wsPathLine] = contents.trim().split('\n');
const port = parseInt(portLine, 10);
// ...
const endpoint = `ws://localhost:${port}${wsPathLine?.trim() || '/devtools/browser'}`;

I built this against main (df99ada) and checked it:

  • repro.js above: 1.64.1 fails with the error shown; the patched build prints connected, contexts: 1. The same works with CHROME_CONFIG_HOME set instead of XDG_CONFIG_HOME.
  • A new test in tests/library/chromium/connect-over-cdp.spec.ts (launches a persistent context with --remote-debugging-port=0 under $XDG_CONFIG_HOME/google-chrome and connects from a child process) fails without the change with the error above, and passes with it.
  • npm run ctest -- connect-over-cdp: no new failures (CD-004 fails on main in my environment as well).

I would like to submit the PR for this myself. Please assign this issue to me before any automated fix is attempted. The branch and the test are ready, and I will not open the PR until the issue is assigned to me.

I searched the tracker for XDG_CONFIG_HOME, CHROME_CONFIG_HOME, DevToolsActivePort and connectOverCDP chrome channel; no existing issue covers this.

Environment

System:
  OS: Linux 7.0 Ubuntu 24.04.5 LTS 24.04.5 LTS (Noble Numbat)
  CPU: (24) x64 Intel(R) Core(TM) Ultra 9 275HX
  Memory: 37.52 GB / 62.25 GB
Binaries:
  Node: 22.23.4
  npm: 9.2.0
npmPackages:
  playwright-core: ^1.64.1 => 1.64.1
Browsers:
  Google Chrome: 156.0.8078.47

Activity

  1. github-actions commented on Nov 3, 2026

    @github-actions
  2. microsoft-playwright-automation commented on Nov 3, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot and I reproduced this on Linux.

    Reproduced on 1.65.0-next, commit b2f7011c5653c9acb4269eacc617dfce3c7b1545, with Chromium 158.0.8127.2. Both reported problems are present: channel lookup ignores the Linux config variables, and correcting the directory alone still gives a WebSocket 404 because the second line of DevToolsActivePort is ignored.

    The proposed fix honors CHROME_CONFIG_HOME before XDG_CONFIG_HOME in both directory tables and uses the WebSocket path from the file, with the existing fallback for port-only files. The existing CDP connection test now covers the report.

    Reproduction and checks

    The test launches a persistent Chromium context in a temporary <configHome>/google-chrome directory with --remote-debugging-port=0. A fresh Node process then calls chromium.connectOverCDP('chrome') with:

    • XDG_CONFIG_HOME=<configHome> and an empty CHROME_CONFIG_HOME.
    • CHROME_CONFIG_HOME=<configHome> and XDG_CONFIG_HOME pointing elsewhere, to check precedence.

    On unchanged production code, the first connection fails looking under ~/.config. With only the directory correction, it fails at /devtools/browser with 404. With the full fix, both connections report one browser context.

    On Ubuntu 24.04.5:

    • Extended CD-001: passes headless and headed.
    • connect-over-cdp and neighboring connect-to-worker suites: 38 passed, 1 existing skipped test.
    • CLI CDP suite: 13 passed.
    • Actual playwright-cli list --all --json: finds the temporary Chrome profile and its endpoint with each environment configuration.
    • npm run build and npm run flint: passed.

    This is a Chromium-only API; Firefox and WebKit do not support this connection method. Other operating systems and the reported 1.64.1 release were not run because the failure reproduced on current source.

    Draft PR: #43884

    Triaged on Linux by the Playwright bot - agent run

  3. rickardof commented on Nov 3, 2026

    @rickardof
    Author

    I opened #43885 with the fix and a test. I said I would wait for the assignment, but I'm opening it now because the draft #43884 appeared for this issue. I'd like to carry it through and will address review comments.

  4. rickardof commented on Nov 3, 2026

    @rickardof
    Author

    Thanks for looking at this. I saw #43885 was closed, and I'm fine with #43884 landing. I'd like to keep contributing to Playwright: what's the best way for an outside contributor to get a bug fix accepted, given that triage now proposes fixes automatically? Should I wait for an assignment, or is there a kind of issue you'd prefer contributors to pick up?

  5. added a commit that references this issue on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions