Skip to content

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

fix(server): close browsers when PlaywrightServer shuts down (#40294)

Pavel Feldman0980ce62c563
diff --git a/packages/playwright-core/src/remote/playwrightServer.ts b/packages/playwright-core/src/remote/playwrightServer.ts
index c3b0058596..7c45778cb9 100644
--- a/packages/playwright-core/src/remote/playwrightServer.ts
+++ b/packages/playwright-core/src/remote/playwrightServer.ts
@@ -319,6 +319,10 @@ export class PlaywrightServer {
async close() {
await this._wsServer.close();
+ // Close all browsers that were launched by this server (e.g. in reuse mode)
+ // to avoid leaking browser processes that may hold connections to test servers.
+ for (const browser of this._playwright.allBrowsers())
+ await browser.close(nullProgress, { reason: 'Server closed' });
}
}