chore: don't close other browsers in reuse-browsers mode (#36383)

Signed-off-by: Simon Knott <info@simonknott.de>
Co-authored-by: Dmitry Gozman <dgozman@gmail.com>
This commit is contained in:
Simon Knott 2025-06-23 08:46:04 +02:00 committed by GitHub
parent 41bcfc9986
commit ed7e552006
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 10 deletions

View File

@ -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');
}
}
};