Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(cli): isolate sockets by users (#39518)
Pavel Feldman7a01f2e20ce5
diff --git a/packages/playwright-core/src/cli/client/devtoolsApp.ts b/packages/playwright-core/src/cli/client/devtoolsApp.tsindex 4143302b32..b479cd9d85 100644--- a/packages/playwright-core/src/cli/client/devtoolsApp.ts+++ b/packages/playwright-core/src/cli/client/devtoolsApp.ts@@ -19,11 +19,12 @@ import path from 'path';import os from 'os';import net from 'net';+import { chromium } from '../../..';import { HttpServer } from '../../server/utils/httpServer';import { gracefullyProcessExitDoNotHang } from '../../server/utils/processLauncher';import { findChromiumChannelBestEffort, registryDirectory } from '../../server/registry/index';-+import { calculateSha1 } from '../../utils';import { createClientInfo, Registry } from './registry';import { Session } from './session';@@ -213,9 +214,10 @@ function socketsDirectory() {}function devtoolsSocketPath() {+ const userNameHash = calculateSha1(process.env.USERNAME || 'default').slice(0, 8);return process.platform === 'win32'- ? `\\\\.\\pipe\\playwright-devtools-${process.env.USERNAME || 'default'}`- : path.join(socketsDirectory(), 'devtools.sock');+ ? `\\\\.\\pipe\\playwright-devtools-${userNameHash}`+ : path.join(socketsDirectory(), `devtools-${userNameHash}.sock`);}async function acquireSingleton(): Promise<net.Server> {diff --git a/packages/playwright-core/src/cli/client/program.ts b/packages/playwright-core/src/cli/client/program.tsindex 2eff9ad027..5b10e82ae6 100644--- a/packages/playwright-core/src/cli/client/program.ts+++ b/packages/playwright-core/src/cli/client/program.ts@@ -19,6 +19,7 @@import { execSync, spawn } from 'child_process';+import crypto from 'crypto';import fs from 'fs';import os from 'os';import path from 'path';@@ -298,7 +299,8 @@ async function findOrInstallDefaultBrowser() {}function daemonSocketPath(clientInfo: ClientInfo, sessionName: string): string {- const socketName = `${sessionName}.sock`;+ const userNameHash = calculateSha1(process.env.USERNAME || 'default').slice(0, 8);+ const socketName = `${sessionName}-${userNameHash}.sock`;if (os.platform() === 'win32')return `\\\\.\\pipe\\${clientInfo.workspaceDirHash}-${socketName}`;const socketsDir = process.env.PLAYWRIGHT_DAEMON_SOCKETS_DIR || path.join(os.tmpdir(), 'playwright-cli');@@ -442,3 +444,9 @@ async function renderSessionStatus(clientInfo: ClientInfo, session: Session) {text.push(...renderResolvedConfig(config.resolvedConfig));return text.join('\n');}++export function calculateSha1(buffer: Buffer | string): string {+ const hash = crypto.createHash('sha1');+ hash.update(buffer);+ return hash.digest('hex');+}