File tree Expand file tree Collapse file tree
apps/playwright-browser-tunnel/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22// See LICENSE in the project root for license information.
33
44import type { ChildProcess } from 'node:child_process' ;
5+ import { once } from 'node:events' ;
56
67import type { BrowserServer , BrowserType , LaunchOptions } from 'playwright-core' ;
78import { type RawData , WebSocket , type WebSocketServer } from 'ws' ;
@@ -122,15 +123,13 @@ export class PlaywrightTunnel {
122123
123124 public async waitForCloseAsync ( ) : Promise < void > {
124125 const terminal : ITerminal = this . _terminal ;
125- await new Promise < void > ( ( resolve ) => {
126- void this . _initWsPromise ?. then ( ( ws ) => {
127- ws . on ( 'close' , ( ) => {
128- terminal . writeLine ( 'WebSocket connection closed. resolving init promise.' ) ;
129- this . _initWsPromise = undefined ;
130- resolve ( ) ;
131- } ) ;
132- } ) ;
133- } ) ;
126+ const initWsPromise : Promise < WebSocket > | undefined = this . _initWsPromise ;
127+ if ( initWsPromise ) {
128+ const ws : WebSocket = await initWsPromise ;
129+ await once ( ws , 'close' ) ;
130+ terminal . writeLine ( 'WebSocket connection closed. resolving init promise.' ) ;
131+ this . _initWsPromise = undefined ;
132+ }
134133 }
135134
136135 public async startAsync ( options : { keepRunning ?: boolean } = { } ) : Promise < void > {
You can’t perform that action at this time.
0 commit comments