diff --git a/src/server/android/android.ts b/src/server/android/android.ts index a69780d9dfb96..cac265bce52aa 100644 --- a/src/server/android/android.ts +++ b/src/server/android/android.ts @@ -119,6 +119,7 @@ export class AndroidDevice extends EventEmitter { constructor(android: Android, backend: DeviceBackend, model: string) { super(); + this.setMaxListeners(0); this._android = android; this._backend = backend; this.model = model; @@ -385,6 +386,7 @@ class AndroidBrowser extends EventEmitter { constructor(device: AndroidDevice, socket: SocketBackend) { super(); + this.setMaxListeners(0); this.device = device; this._socket = socket; this._socket.on('close', () => { diff --git a/src/server/android/backendAdb.ts b/src/server/android/backendAdb.ts index c0494a8a99989..8709087da3d78 100644 --- a/src/server/android/backendAdb.ts +++ b/src/server/android/backendAdb.ts @@ -109,6 +109,7 @@ class BufferedSocketWrapper extends EventEmitter implements SocketBackend { constructor(command: string, socket: net.Socket) { super(); + this.setMaxListeners(0); this._command = command; this._socket = socket; this._connectPromise = new Promise(f => this._socket.on('connect', f)); diff --git a/src/server/browser.ts b/src/server/browser.ts index 5b61654f71fbc..ed2736ddb7e56 100644 --- a/src/server/browser.ts +++ b/src/server/browser.ts @@ -61,6 +61,7 @@ export abstract class Browser extends EventEmitter { constructor(options: BrowserOptions) { super(); + this.setMaxListeners(0); this.options = options; } diff --git a/src/server/browserContext.ts b/src/server/browserContext.ts index db1e93aa0dce5..4e9e8e77a90a7 100644 --- a/src/server/browserContext.ts +++ b/src/server/browserContext.ts @@ -123,6 +123,7 @@ export abstract class BrowserContext extends EventEmitter { constructor(browser: Browser, options: types.BrowserContextOptions, browserContextId: string | undefined) { super(); + this.setMaxListeners(0); this._browser = browser; this._options = options; this._browserContextId = browserContextId; diff --git a/src/server/chromium/crConnection.ts b/src/server/chromium/crConnection.ts index 117852abab79a..c590a3acce698 100644 --- a/src/server/chromium/crConnection.ts +++ b/src/server/chromium/crConnection.ts @@ -43,6 +43,7 @@ export class CRConnection extends EventEmitter { constructor(transport: ConnectionTransport, protocolLogger: ProtocolLogger, browserLogsCollector: RecentLogsCollector) { super(); + this.setMaxListeners(0); this._transport = transport; this._protocolLogger = protocolLogger; this._browserLogsCollector = browserLogsCollector; @@ -139,6 +140,7 @@ export class CRSession extends EventEmitter { constructor(connection: CRConnection, rootSessionId: string, targetType: string, sessionId: string) { super(); + this.setMaxListeners(0); this._connection = connection; this._rootSessionId = rootSessionId; this._targetType = targetType; diff --git a/src/server/electron/electron.ts b/src/server/electron/electron.ts index 91f2ff6bbbf4a..1ff8a131a09ad 100644 --- a/src/server/electron/electron.ts +++ b/src/server/electron/electron.ts @@ -65,6 +65,7 @@ export class ElectronApplication extends EventEmitter { constructor(browser: CRBrowser, nodeConnection: CRConnection) { super(); + this.setMaxListeners(0); this._browserContext = browser._defaultContext as CRBrowserContext; this._browserContext.on(BrowserContext.Events.Close, () => { // Emit application closed after context closed. diff --git a/src/server/firefox/ffConnection.ts b/src/server/firefox/ffConnection.ts index c65777e35c1d8..7de9c38cc2339 100644 --- a/src/server/firefox/ffConnection.ts +++ b/src/server/firefox/ffConnection.ts @@ -49,6 +49,7 @@ export class FFConnection extends EventEmitter { constructor(transport: ConnectionTransport, protocolLogger: ProtocolLogger, browserLogsCollector: RecentLogsCollector) { super(); + this.setMaxListeners(0); this._transport = transport; this._protocolLogger = protocolLogger; this._browserLogsCollector = browserLogsCollector; @@ -162,6 +163,7 @@ export class FFSession extends EventEmitter { constructor(connection: FFConnection, targetType: string, sessionId: string, rawSend: (message: any) => void) { super(); + this.setMaxListeners(0); this._callbacks = new Map(); this._connection = connection; this._targetType = targetType; diff --git a/src/server/network.ts b/src/server/network.ts index e44443d8f206c..d70a677f063f3 100644 --- a/src/server/network.ts +++ b/src/server/network.ts @@ -355,6 +355,7 @@ export class WebSocket extends EventEmitter { constructor(url: string) { super(); + this.setMaxListeners(0); this._url = url; } diff --git a/src/server/page.ts b/src/server/page.ts index 4633993ba2e19..d386bdb1ce150 100644 --- a/src/server/page.ts +++ b/src/server/page.ts @@ -508,6 +508,7 @@ export class Worker extends EventEmitter { constructor(url: string) { super(); + this.setMaxListeners(0); this._url = url; this._executionContextCallback = () => {}; this._executionContextPromise = new Promise(x => this._executionContextCallback = x); diff --git a/src/server/supplements/recorder/recorderApp.ts b/src/server/supplements/recorder/recorderApp.ts index ea99c1f07104a..59ca1cb0cf2e6 100644 --- a/src/server/supplements/recorder/recorderApp.ts +++ b/src/server/supplements/recorder/recorderApp.ts @@ -28,11 +28,11 @@ import { DEFAULT_ARGS } from '../../chromium/chromium'; const readFileAsync = util.promisify(fs.readFile); export class RecorderApp extends EventEmitter { - private _page: Page; constructor(page: Page) { super(); + this.setMaxListeners(0); this._page = page; } diff --git a/src/server/webkit/wkConnection.ts b/src/server/webkit/wkConnection.ts index ba90a288cdb3f..8b9f623eeea25 100644 --- a/src/server/webkit/wkConnection.ts +++ b/src/server/webkit/wkConnection.ts @@ -111,6 +111,7 @@ export class WKSession extends EventEmitter { constructor(connection: WKConnection, sessionId: string, errorText: string, rawSend: (message: any) => void) { super(); + this.setMaxListeners(0); this.connection = connection; this.sessionId = sessionId; this._rawSend = rawSend; diff --git a/test/browsertype-connect.spec.ts b/test/browsertype-connect.spec.ts index 5ad47a7574c61..04535f2bc5b77 100644 --- a/test/browsertype-connect.spec.ts +++ b/test/browsertype-connect.spec.ts @@ -256,4 +256,18 @@ describe('connect', (suite, { mode }) => { const files = fs.readdirSync(videosPath); expect(files.some(file => file.endsWith('webm'))).toBe(true); }); + + it('should be able to connect 20 times to a single server without warnings', async ({browserType, remoteServer, server}) => { + let warning = null; + const warningHandler = w => warning = w; + process.on('warning', warningHandler); + + const browsers = []; + for (let i = 0; i < 20; i++) + browsers.push(await browserType.connect({ wsEndpoint: remoteServer.wsEndpoint() })); + await Promise.all([browsers.map(browser => browser.close())]); + + process.off('warning', warningHandler); + expect(warning).toBe(null); + }); });