mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-07-27 00:52:27 +08:00
Fix race condition in session file initialization by chaining file operations
Co-authored-by: pavelfeldman <883973+pavelfeldman@users.noreply.github.com>
This commit is contained in:
parent
9588845cc3
commit
bb9de30ef9
@ -45,6 +45,7 @@ export class Context {
|
|||||||
private _pendingAction: PendingAction | undefined;
|
private _pendingAction: PendingAction | undefined;
|
||||||
private _downloads: { download: playwright.Download, finished: boolean, outputFile: string }[] = [];
|
private _downloads: { download: playwright.Download, finished: boolean, outputFile: string }[] = [];
|
||||||
private _sessionFile: string | undefined;
|
private _sessionFile: string | undefined;
|
||||||
|
private _sessionFileInitialized: Promise<void> | undefined;
|
||||||
clientVersion: { name: string; version: string; } | undefined;
|
clientVersion: { name: string; version: string; } | undefined;
|
||||||
|
|
||||||
constructor(tools: Tool[], config: FullConfig, browserContextFactory: BrowserContextFactory) {
|
constructor(tools: Tool[], config: FullConfig, browserContextFactory: BrowserContextFactory) {
|
||||||
@ -53,7 +54,7 @@ export class Context {
|
|||||||
this._browserContextFactory = browserContextFactory;
|
this._browserContextFactory = browserContextFactory;
|
||||||
testDebug('create context');
|
testDebug('create context');
|
||||||
if (this.config.saveSession)
|
if (this.config.saveSession)
|
||||||
void this._initializeSessionFile();
|
this._sessionFileInitialized = this._initializeSessionFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
clientSupportsImages(): boolean {
|
clientSupportsImages(): boolean {
|
||||||
@ -150,6 +151,10 @@ export class Context {
|
|||||||
if (!this.config.saveSession || !this._sessionFile)
|
if (!this.config.saveSession || !this._sessionFile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Ensure session file is initialized before proceeding
|
||||||
|
if (this._sessionFileInitialized)
|
||||||
|
await this._sessionFileInitialized;
|
||||||
|
|
||||||
const entry = [
|
const entry = [
|
||||||
`- ${toolName}:`,
|
`- ${toolName}:`,
|
||||||
' params:',
|
' params:',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user