Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(cli): avoid race between socket write callback and response (#38983)

Dmitry Gozmanf186a8939434
diff --git a/packages/playwright/src/mcp/terminal/program.ts b/packages/playwright/src/mcp/terminal/program.ts
index 0f621001c0..59069812be 100644
--- a/packages/playwright/src/mcp/terminal/program.ts
+++ b/packages/playwright/src/mcp/terminal/program.ts
@@ -63,10 +63,11 @@ class Session {
method,
params,
};
- await this._connection.send(message);
- return new Promise<any>((resolve, reject) => {
+ const responsePromise = new Promise<any>((resolve, reject) => {
this._callbacks.set(messageId, { resolve, reject });
});
+ const [result] = await Promise.all([responsePromise, this._connection.send(message)]);
+ return result;
}
close() {