Skip to content

Commit

Permalink
possible fix for windows hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
ebebbington committed Apr 28, 2024
1 parent b8aa82f commit f24e1ef
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ export class Client {
return;
}

// Collect all promises we need to wait for due to the browser and any page websockets
// Only needed for windows...
const pList = this.#pages.map((_page) => deferred());
pList.push(deferred());
this.#pages.forEach((page, i) => {
page.socket.onclose = () => pList[i].resolve();
});
this.#protocol.socket.onclose = () => pList.at(-1)?.resolve();

// Close browser process (also closes the ws endpoint, which in turn closes all sockets)
if (this.#browser_process) {
this.#browser_process.stderr!.cancel();
Expand All @@ -185,11 +194,10 @@ export class Client {
await this.#browser_process.status;
} else {
// When Working with Remote Browsers, where we don't control the Browser Process explicitly
const p = deferred()
this.#protocol.socket.onclose = () => p.resolve()
await this.#protocol.send("Browser.close");
await p
}

await Promise.all(pList)

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

0 comments on commit f24e1ef

Please sign in to comment.