@@ -177,6 +177,15 @@ export class Client {
177
177
return ;
178
178
}
179
179
180
+ // Collect all promises we need to wait for due to the browser and any page websockets
181
+ // Only needed for windows...
182
+ const pList = this . #pages. map ( ( _page ) => deferred ( ) ) ;
183
+ pList . push ( deferred ( ) ) ;
184
+ this . #pages. forEach ( ( page , i ) => {
185
+ page . socket . onclose = ( ) => pList [ i ] . resolve ( ) ;
186
+ } ) ;
187
+ this . #protocol. socket . onclose = ( ) => pList . at ( - 1 ) ?. resolve ( ) ;
188
+
180
189
// Close browser process (also closes the ws endpoint, which in turn closes all sockets)
181
190
if ( this . #browser_process) {
182
191
this . #browser_process. stderr ! . cancel ( ) ;
@@ -185,11 +194,10 @@ export class Client {
185
194
await this . #browser_process. status ;
186
195
} else {
187
196
// When Working with Remote Browsers, where we don't control the Browser Process explicitly
188
- const p = deferred ( )
189
- this . #protocol. socket . onclose = ( ) => p . resolve ( )
190
197
await this . #protocol. send ( "Browser.close" ) ;
191
- await p
192
198
}
199
+
200
+ await Promise . all ( pList )
193
201
194
202
// Zombie processes is a thing with Windows, the firefox process on windows
195
203
// will not actually be closed using the above.
@@ -287,7 +295,6 @@ export class Client {
287
295
const line of browserProcess . stderr . pipeThrough ( new TextDecoderStream ( ) )
288
296
. pipeThrough ( new TextLineStream ( ) )
289
297
) { // Loop also needed before json endpoint is up
290
- console . log ( line ) ;
291
298
const match = line . match ( / ^ D e v T o o l s l i s t e n i n g o n ( w s : \/ \/ .* ) $ / ) ;
292
299
if ( ! match ) {
293
300
continue ;
0 commit comments