diff --git a/packages/client/hmi-client/src/services/jupyter.ts b/packages/client/hmi-client/src/services/jupyter.ts index 41f4af880b..bc21e77c3e 100644 --- a/packages/client/hmi-client/src/services/jupyter.ts +++ b/packages/client/hmi-client/src/services/jupyter.ts @@ -280,6 +280,7 @@ export class KernelSessionManager { console.log('waiting...', this.jupyterSession?.session?.kernel); counter++; if (this.jupyterSession?.session?.kernel) { + window.addEventListener('beforeunload', this.shutdown.bind(this)); // bind(this) ensures that this instance of the class is used clearInterval(id); resolve(true); } @@ -318,6 +319,7 @@ export class KernelSessionManager { } shutdown() { + window.removeEventListener('beforeunload', this.shutdown.bind(this)); // bind(this) ensures that this instance of the class is used this.jupyterSession?.shutdown(); } }