fix: clear CDP proxy startup error listener (#2876)

This commit is contained in:
Neil 2026-05-26 20:13:56 -07:00 committed by GitHub
parent 3134496a6d
commit 57990fdcf3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -94,6 +94,14 @@ describe('CdpWsProxy', () => {
expect(proxy.getPort()).toBeGreaterThan(0)
})
it('does not retain an extra startup server error listener after binding', () => {
const server = (
proxy as unknown as { httpServer: { listenerCount: (event: string) => number } }
).httpServer
expect(server.listenerCount('error')).toBeLessThanOrEqual(1)
})
it('attaches debugger on start', () => {
expect(mock.webContents.debugger.attach).toHaveBeenCalledWith('1.3')
})

View File

@ -24,6 +24,9 @@ export class CdpWsProxy {
return new Promise<string>((resolve, reject) => {
this.httpServer = createServer((req, res) => this.handleHttpRequest(req, res))
this.wss = new WebSocketServer({ server: this.httpServer })
const onListenError = (error: Error): void => {
reject(error)
}
this.wss.on('connection', (ws) => {
if (this.client) {
this.client.close()
@ -37,6 +40,7 @@ export class CdpWsProxy {
})
})
this.httpServer.listen(0, '127.0.0.1', () => {
this.httpServer?.removeListener('error', onListenError)
const addr = this.httpServer!.address()
if (typeof addr === 'object' && addr) {
this.port = addr.port
@ -45,7 +49,7 @@ export class CdpWsProxy {
reject(new Error('Failed to bind proxy server'))
}
})
this.httpServer.on('error', reject)
this.httpServer.once('error', onListenError)
})
}