Skip to content

Commit bb46da6

Browse files
committed
fix(cli): do not pass PLAYWRIGHT_CLI_SESSION as daemon --endpoint
PLAYWRIGHT_CLI_SESSION is the env-var equivalent of -s/--session (the session name). It is already consumed as such in startDaemon via resolveSessionName. The leftover else-if branch additionally re-passed it as the daemon's --endpoint= argument when mode is 'attach', which made the daemon try to connect to a socket at the literal session-name path. Repro: PLAYWRIGHT_CLI_SESSION=myname playwright-cli attach --cdp=http://127.0.0.1:99999 -> Error: Daemon pid=...: connect ENOENT myname The fallback dates back to #39650, when PLAYWRIGHT_CLI_SESSION only meant "endpoint to attach to". After #39707 it gained its current session-name meaning, but the obsolete fallback survived through the --attach -> --endpoint rename (#39972) and the mode-guard refactor (#40176). Fixes microsoft/playwright-cli#414
1 parent e32f907 commit bb46da6

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

packages/playwright-core/src/tools/cli-client/session.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ export class Session {
139139
args.push(`--cdp=${cliArgs.cdp}`);
140140
if (cliArgs.endpoint)
141141
args.push(`--endpoint=${cliArgs.endpoint}`);
142-
else if (mode === 'attach' && process.env.PLAYWRIGHT_CLI_SESSION)
143-
args.push(`--endpoint=${process.env.PLAYWRIGHT_CLI_SESSION}`);
144142

145143
const child = spawn(process.execPath, args, {
146144
detached: true,

tests/mcp/cli-cdp.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ test('attach via cdp URL keeps the default session', async ({ cdpServer, cli, se
5757
expect(listOutput).toContain('(attached)');
5858
});
5959

60+
test('attach via cdp URL honors PLAYWRIGHT_CLI_SESSION as session name', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright-cli/issues/414' } }, async ({ cdpServer, cli }) => {
61+
await cdpServer.start();
62+
const { exitCode } = await cli('attach', `--cdp=${cdpServer.endpoint}`, { env: { PLAYWRIGHT_CLI_SESSION: 'myname' } });
63+
expect(exitCode).toBe(0);
64+
});
65+
6066
test('detach tears down an attached session', async ({ cdpServer, cli }) => {
6167
await cdpServer.start();
6268

0 commit comments

Comments
 (0)