diff --git a/src/browserServerImpl.ts b/src/browserServerImpl.ts index 7793bdb010..a5a9bd8e14 100644 --- a/src/browserServerImpl.ts +++ b/src/browserServerImpl.ts @@ -97,7 +97,7 @@ export class BrowserServerLauncherImpl implements BrowserServerLauncher { portForwardingServer.enablePortForwarding(ports); }); const incomingSocksSocketHandler = (socket: SocksInterceptedSocketHandler) => { - playwrightDispatcher._dispatchEvent('incomingSocksSocket', { socket: new SocksSocketDispatcher(playwrightDispatcher._scope, socket) }); + playwrightDispatcher._dispatchEvent('incomingSocksSocket', { socket: new SocksSocketDispatcher(playwrightDispatcher, socket) }); }; portForwardingServer.on('incomingSocksSocket', incomingSocksSocketHandler); diff --git a/src/client/browserType.ts b/src/client/browserType.ts index 4d5854cc52..10122efd08 100644 --- a/src/client/browserType.ts +++ b/src/client/browserType.ts @@ -189,6 +189,7 @@ export class BrowserType extends ChannelOwner this._socket.end()); + assert(parent instanceof Playwright); + + assert(parent._forwardPorts.includes(this._initializer.dstPort)); + assert(isLocalIpAddress(this._initializer.dstAddr)); if (isUnderTest() && process.env.PW_TEST_PROXY_TARGET) this._initializer.dstPort = Number(process.env.PW_TEST_PROXY_TARGET); - assert(isLocalIpAddress(this._initializer.dstAddr)); this._socket = net.createConnection(this._initializer.dstPort, this._initializer.dstAddr); this._socket.on('error', (err: Error) => this._channel.error({error: String(err)})); @@ -50,6 +53,8 @@ export class SocksSocket extends ChannelOwner this._socket.end()); + + this._connection.on('disconnect', () => this._socket.end()); } async write(data: Buffer): Promise {