diff --git a/server.cjs b/server.cjs index 82021ad..fcd4f33 100644 --- a/server.cjs +++ b/server.cjs @@ -182,7 +182,15 @@ function startServer() { } } - sendPortUpdates(); + async function init() { + if (process.env["XTERM_CONFIRM_BROWSER_EXIT"] === "true") { + ws.send(JSON.stringify({ action: "confirmExit" })); + } + + sendPortUpdates(); + } + + init(); }); let clientForExternalMessages = null; diff --git a/src/lib/remote.ts b/src/lib/remote.ts index ee7e588..2c8d5d0 100644 --- a/src/lib/remote.ts +++ b/src/lib/remote.ts @@ -66,6 +66,13 @@ export const initiateRemoteCommunicationChannelSocket = async (protocol: string) output(`Port ${port} has been opened`, { formActions: [openUrlButton], reason: "info" }); break; } + case "confirmExit": { + // Ask for confirmation before closing the current terminal session + window.onbeforeunload = (e: BeforeUnloadEvent) => { + e.preventDefault(); + e.returnValue = "Are you sure you want to close the terminal?"; + }; + } default: console.debug("Unhandled message", messageData); }