Skip to content

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

fix(listeners): avoid "too many listeners" problem safely (#4223)

Pavel Feldmanc97af3ee9165
diff --git a/src/server/processLauncher.ts b/src/server/processLauncher.ts
index b19281a7a0..883f524e15 100644
--- a/src/server/processLauncher.ts
+++ b/src/server/processLauncher.ts
@@ -58,6 +58,12 @@ export async function gracefullyCloseAll() {
await Promise.all(Array.from(gracefullyCloseSet).map(gracefullyClose => gracefullyClose().catch(e => {})));
}
+// We currently spawn a process per page when recording video in Chromium.
+// This triggers "too many listeners" on the process object once you have more than 10 pages open.
+const maxListeners = process.getMaxListeners();
+if (maxListeners !== 0)
+ process.setMaxListeners(Math.max(maxListeners || 0, 100));
+
export async function launchProcess(options: LaunchProcessOptions): Promise<LaunchResult> {
const cleanup = () => helper.removeFolders(options.tempDirectories);