Does it "OnDestroy" on closing the browser?


We want to call an action e.g. to clear session (customized) on the OnDestroy event. Just wondering if it triggers on closing the browser.



When you close your browser, the session should also end (so long as you don't have another window open), regardless if your OnDestroy event gets triggered or not.

You can use the OnDestroy event of the BottomBar block. But, can you give us more details about your scenario case?

Basically we don't have a login and just use Session Tokens when the user accesses a specific transaction. The screens are anonymous. When the user accesses the transaction in a proper way, a token is created and is stored in the database with reference to that transaction id. On 'logout', there is a process that basically deletes this record so that it will invalidate the 'session'.

I am already calling this 'logout' process on the OnDestroy event of a screen. Now just wondering if this triggers when you close the browser.

Yes, when you close the browser, will be trigger the OnDestroy, and clean DOM.

Nuno Miguel Verdasca wrote:

Yes, when you close the browser, will be trigger the OnDestroy, and clean DOM.

Although now we tried a pure JS approach, still had to try this one out. Unfortunately, didn't work. Created a screen action OnDestroy for a screen and just call a CreateEntity for a record. Moving out of that screen created a new record. Closing the browser didn't.

Rank: #2866

Hi Juan Carlos,

Did you manage to find a clear answer to your question?

From my tests with OnDestroy, I saw that indeed it doesn't get triggered when closing the browser, but I was wondering if this is the expected behaviour or I'm doing something wrong, haha.


Rank: #475

No, the OnDestroy event does not trigger when the browser or browser tab is closed. The event is only called when navigating to another Screen within a Reactive (or Mobile) application.

From the docs:

The On Destroy event handler executes when the Screen or Block is going to be destroyed. 

In Screens, this event happens when the transition to the new Screen ends.

In Blocks, this event happens before the Block is removed from the DOM.


For Juan Carlos' original use-case, the best solution is to:

  • Store the time of last activity associated with each user 'session'.
    This could be updated with every user operation in the app, or only for some operations.
  • Monitor inactive sessions using a Timer or other background process, and clean these up after a set time (ex. 8h of inactivity).