File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -182,7 +182,15 @@ function startServer() {
182182 }
183183 }
184184
185- sendPortUpdates ( ) ;
185+ async function init ( ) {
186+ if ( process . env [ "XTERM_CONFIRM_BROWSER_EXIT" ] === "true" ) {
187+ ws . send ( JSON . stringify ( { action : "confirmExit" } ) ) ;
188+ }
189+
190+ sendPortUpdates ( ) ;
191+ }
192+
193+ init ( ) ;
186194 } ) ;
187195
188196 let clientForExternalMessages = null ;
Original file line number Diff line number Diff line change @@ -66,6 +66,13 @@ export const initiateRemoteCommunicationChannelSocket = async (protocol: string)
6666 output ( `Port ${ port } has been opened` , { formActions : [ openUrlButton ] , reason : "info" } ) ;
6767 break ;
6868 }
69+ case "confirmExit" : {
70+ // Ask for confirmation before closing the current terminal session
71+ window . onbeforeunload = ( e : BeforeUnloadEvent ) => {
72+ e . preventDefault ( ) ;
73+ e . returnValue = "Are you sure you want to close the terminal?" ;
74+ } ;
75+ }
6976 default :
7077 console . debug ( "Unhandled message" , messageData ) ;
7178 }
You can’t perform that action at this time.
0 commit comments