Preventing the browser page to be reloaded while some (Python) code is running (asynchronously)?

Hi all,
I have an application that requires some settings to be properly restored after the job is done. How I can prevent (or at least control) things like browser page reloading, kernel interrupt or restart? Is there a hook mechanism somewhere in JupyterLab that I could use to implement such a feature? Thanks.