@@ -24,10 +24,12 @@ import { registryDirectory } from 'playwright-core/lib/server/registry/index';
2424import { startTraceViewerServer } from 'playwright-core/lib/server' ;
2525import { findBrowserProcess , getBrowserExecPath } from './processUtils' ;
2626import { logUnhandledError , testDebug } from '../log' ;
27- import { outputFile } from './config' ;
27+ import { outputFile } from './config' ;
28+ import { firstRootPath } from '../sdk/server' ;
2829
2930import type { FullConfig } from './config' ;
3031import type { LaunchOptions } from '../../../../playwright-core/src/client/types' ;
32+ import type { ClientInfo } from '../sdk/server' ;
3133
3234export function contextFactory ( config : FullConfig ) : BrowserContextFactory {
3335 if ( config . browser . remoteEndpoint )
@@ -39,8 +41,6 @@ export function contextFactory(config: FullConfig): BrowserContextFactory {
3941 return new PersistentContextFactory ( config ) ;
4042}
4143
42- export type ClientInfo = { name ?: string , version ?: string , rootPath ?: string } ;
43-
4444export interface BrowserContextFactory {
4545 createContext ( clientInfo : ClientInfo , abortSignal : AbortSignal , toolName : string | undefined ) : Promise < { browserContext : playwright . BrowserContext , close : ( ) => Promise < void > } > ;
4646}
@@ -105,7 +105,7 @@ class IsolatedContextFactory extends BaseContextFactory {
105105 protected override async _doObtainBrowser ( clientInfo : ClientInfo ) : Promise < playwright . Browser > {
106106 await injectCdpPort ( this . config . browser ) ;
107107 const browserType = playwright [ this . config . browser . browserName ] ;
108- const tracesDir = await outputFile ( this . config , clientInfo . rootPath , `traces` ) ;
108+ const tracesDir = await outputFile ( this . config , clientInfo , `traces` ) ;
109109 if ( this . config . saveTrace )
110110 await startTraceServer ( this . config , tracesDir ) ;
111111 return browserType . launch ( {
@@ -171,8 +171,8 @@ class PersistentContextFactory implements BrowserContextFactory {
171171 async createContext ( clientInfo : ClientInfo ) : Promise < { browserContext : playwright . BrowserContext , close : ( ) => Promise < void > } > {
172172 await injectCdpPort ( this . config . browser ) ;
173173 testDebug ( 'create browser context (persistent)' ) ;
174- const userDataDir = this . config . browser . userDataDir ?? await this . _createUserDataDir ( clientInfo . rootPath ) ;
175- const tracesDir = await outputFile ( this . config , clientInfo . rootPath , `traces` ) ;
174+ const userDataDir = this . config . browser . userDataDir ?? await this . _createUserDataDir ( clientInfo ) ;
175+ const tracesDir = await outputFile ( this . config , clientInfo , `traces` ) ;
176176 if ( this . config . saveTrace )
177177 await startTraceServer ( this . config , tracesDir ) ;
178178
@@ -218,10 +218,11 @@ class PersistentContextFactory implements BrowserContextFactory {
218218 testDebug ( 'close browser context complete (persistent)' ) ;
219219 }
220220
221- private async _createUserDataDir ( rootPath : string | undefined ) {
221+ private async _createUserDataDir ( clientInfo : ClientInfo ) {
222222 const dir = process . env . PWMCP_PROFILES_DIR_FOR_TEST ?? registryDirectory ;
223223 const browserToken = this . config . browser . launchOptions ?. channel ?? this . config . browser ?. browserName ;
224224 // Hesitant putting hundreds of files into the user's workspace, so using it for hashing instead.
225+ const rootPath = firstRootPath ( clientInfo ) ;
225226 const rootPathToken = rootPath ? `-${ createHash ( rootPath ) } ` : '' ;
226227 const result = path . join ( dir , `mcp-${ browserToken } ${ rootPathToken } ` ) ;
227228 await fs . promises . mkdir ( result , { recursive : true } ) ;
0 commit comments