From ed7e552006f03d7040d8877f569a1e1bbef79e6f Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Mon, 23 Jun 2025 08:46:04 +0200 Subject: [PATCH] chore: don't close other browsers in reuse-browsers mode (#36383) Signed-off-by: Simon Knott Co-authored-by: Dmitry Gozman --- .../src/remote/playwrightServer.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/playwright-core/src/remote/playwrightServer.ts b/packages/playwright-core/src/remote/playwrightServer.ts index 6eb077fa92..9839cff9b3 100644 --- a/packages/playwright-core/src/remote/playwrightServer.ts +++ b/packages/playwright-core/src/remote/playwrightServer.ts @@ -210,16 +210,13 @@ export class PlaywrightServer { denyLaunch: true, dispose: async () => { // Don't close the pages so that user could debug them, - // but close all the empty browsers and contexts to clean up. - for (const browser of this._playwright.allBrowsers()) { - for (const context of browser.contexts()) { - if (!context.pages().length) - await context.close({ reason: 'Connection terminated' }); - else - await context.stopPendingOperations('Connection closed'); - } - if (!browser.contexts()) - await browser.close({ reason: 'Connection terminated' }); + // but close all the empty contexts to clean up. + // keep around browser so it can be reused by the next connection. + for (const context of browser.contexts()) { + if (!context.pages().length) + await context.close({ reason: 'Connection terminated' }); + else + await context.stopPendingOperations('Connection closed'); } } };