Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/playwright-core/src/tools/mcp/cdpRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import ws, { WebSocketServer as wsServer } from 'ws';
import { ManualPromise } from '@isomorphic/manualPromise';
import { registry } from '../../server/registry/index';

import { findPlaywrightExtensionProfile, playwrightExtensionId } from '../utils/extension';
import { defaultUserDataDir, findPlaywrightExtensionProfile, playwrightExtensionId } from '../utils/extension';
import { addressToString } from '../utils/mcp/http';
import { logUnhandledError } from './log';
import { ExtensionProtocolV2 } from './cdpRelayV2';
Expand Down Expand Up @@ -142,7 +142,7 @@ export class CDPRelayServer {
const testUserDataDir = process.env.PWTEST_EXTENSION_USER_DATA_DIR;
if (testUserDataDir)
args.push(`--user-data-dir=${testUserDataDir}`);
const userDataDir = testUserDataDir ?? this._userDataDir;
const userDataDir = testUserDataDir ?? this._userDataDir ?? defaultUserDataDir(channel);
const profileDirectory = userDataDir ? await findPlaywrightExtensionProfile(userDataDir) : undefined;
if (profileDirectory)
args.push(`--profile-directory=${profileDirectory}`);
Expand Down
29 changes: 29 additions & 0 deletions packages/playwright-core/src/tools/utils/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,42 @@
*/

import fs from 'fs';
import os from 'os';
import path from 'path';

// Also pinned via the "key" field in packages/extension/manifest.json.
export const playwrightExtensionId = 'mmlmfjhmonkocbjadbfplnigmagldckm';

export const playwrightExtensionInstallUrl = `https://chromewebstore.google.com/detail/playwright-extension/${playwrightExtensionId}`;

export function defaultUserDataDir(channel: string): string | undefined {
const home = os.homedir();
switch (os.platform()) {
case 'win32': {
const localAppData = process.env.LOCALAPPDATA;
if (!localAppData)
return undefined;
if (channel === 'chrome')
return path.join(localAppData, 'Google', 'Chrome', 'User Data');
if (channel === 'msedge')
return path.join(localAppData, 'Microsoft', 'Edge', 'User Data');
return undefined;
}
case 'darwin':
if (channel === 'chrome')
return path.join(home, 'Library', 'Application Support', 'Google', 'Chrome');
if (channel === 'msedge')
return path.join(home, 'Library', 'Application Support', 'Microsoft Edge');
return undefined;
default:
if (channel === 'chrome')
return path.join(home, '.config', 'google-chrome');
if (channel === 'msedge')
return path.join(home, '.config', 'microsoft-edge');
return undefined;
}
}

export async function findPlaywrightExtensionProfile(userDataDir: string): Promise<string | undefined> {
const profiles = await listProfileDirectories(userDataDir);
const lastUsed = await readLastUsedProfile(userDataDir);
Expand Down