Skip to content

Commit f24e1ef

Browse files
committed
possible fix for windows hanging
1 parent b8aa82f commit f24e1ef

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/client.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,15 @@ export class Client {
177177
return;
178178
}
179179

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+
180189
// Close browser process (also closes the ws endpoint, which in turn closes all sockets)
181190
if (this.#browser_process) {
182191
this.#browser_process.stderr!.cancel();
@@ -185,11 +194,10 @@ export class Client {
185194
await this.#browser_process.status;
186195
} else {
187196
// 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()
190197
await this.#protocol.send("Browser.close");
191-
await p
192198
}
199+
200+
await Promise.all(pList)
193201

194202
// Zombie processes is a thing with Windows, the firefox process on windows
195203
// will not actually be closed using the above.
@@ -287,7 +295,6 @@ export class Client {
287295
const line of browserProcess.stderr.pipeThrough(new TextDecoderStream())
288296
.pipeThrough(new TextLineStream())
289297
) { // Loop also needed before json endpoint is up
290-
console.log(line);
291298
const match = line.match(/^DevTools listening on (ws:\/\/.*)$/);
292299
if (!match) {
293300
continue;

0 commit comments

Comments
 (0)