Skip to content

Commit

Permalink
Close the launched browser on Ctrl+C when recording (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist authored May 28, 2024
1 parent a243633 commit 1740c99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-coins-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"replayio": patch
---

The launched browser will now get correctly closed on Ctrl+C when recording
3 changes: 3 additions & 0 deletions packages/replayio/src/utils/browser/launchBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export async function launchBrowser(

prompt({
signal: abortControllerForPrompt.signal,
onExit: () => {
spawnDeferred.data.kill();
},
}).then(() => {
spawnDeferred.data.kill();
});
Expand Down
3 changes: 3 additions & 0 deletions packages/replayio/src/utils/prompt/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export async function prompt({
onExit,
signal,
}: {
onExit?: () => void;
signal?: AbortSignal;
} = {}): Promise<boolean> {
return new Promise(resolve => {
Expand Down Expand Up @@ -38,6 +40,7 @@ export async function prompt({
case "\x03":
// \x03 is Ctrl+C (aka "End of text")
// https://donsnotes.com/tech/charsets/ascii.html
onExit?.();
process.exit(0);
default:
resolve(false);
Expand Down

0 comments on commit 1740c99

Please sign in to comment.