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): drop closed browsers from the run-server reuse exclusion set (#43433)

Yury Semikhatskye139b837c204
diff --git a/packages/playwright-core/src/remote/playwrightServer.ts b/packages/playwright-core/src/remote/playwrightServer.ts
index 56f5103c19..800c2d7ff7 100644
--- a/packages/playwright-core/src/remote/playwrightServer.ts
+++ b/packages/playwright-core/src/remote/playwrightServer.ts
@@ -296,7 +296,7 @@ export class PlaywrightServer {
const browserType = this._playwright[browserName as 'chromium'];
const controller = new ProgressController();
const browser = await controller.run(progress => browserType.launch(progress, launchOptions), launchOptions.timeout);
- this._dontReuseBrowsers.add(browser);
+ this._dontReuse(browser);
return {
preLaunchedBrowser: browser,
socksProxy,
diff --git a/tests/library/browsertype-connect.spec.ts b/tests/library/browsertype-connect.spec.ts
index 269745b8d1..757d4da88e 100644
--- a/tests/library/browsertype-connect.spec.ts
+++ b/tests/library/browsertype-connect.spec.ts
@@ -19,7 +19,7 @@ import fs from 'fs';
import type http from 'http';
import type net from 'net';
import * as path from 'path';
-import { utils, getUserAgent, getPlaywrightVersion } from '../../packages/playwright-core/lib/coreBundle';
+import { remote, utils, getUserAgent, getPlaywrightVersion } from '../../packages/playwright-core/lib/coreBundle';
import WebSocket from 'ws';
import { expect, playwrightTest } from '../config/browserTest';
import { ensureSomeFrames, parseTraceRaw, suppressCertificateWarning } from '../config/utils';
@@ -1211,3 +1211,15 @@ test('should timeout after redirect when connecting over http', async ({ connect
expect(error.message).toContain('Timeout 2000ms exceeded.');
await expect.poll(() => aborted).toBe(true);
});
+
+test('should not retain closed browsers in launch mode', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43421' } }, async ({ connect }) => {
+ const server = new remote.PlaywrightServer({ mode: 'default', path: '/' + utils.createGuid(), maxConnections: Number.MAX_VALUE });
+ const wsEndpoint = await server.listen();
+ try {
+ const browser = await connect(wsEndpoint);
+ await browser.close();
+ await expect.poll(() => (server as any)._dontReuseBrowsers.size).toBe(0);
+ } finally {
+ await server.close();
+ }
+});