Run an API call when user closes the app (beforeunload event)

Hi, I would like to make an API call when the user closes the app. I read this topic that says that it's not possible to use listeners because we don't have access to the window.

Also I tried out with a custom component, following this topic, but no luck still.

My goal is to make this API call to prevent users to leave the app without saving some changes to the database. I was looking forward to use the javascript beforeunload event.

Is there a way to achieve this? FYI I thought about using onBlur, on close event handler in some components, but they wouldn't work the way I need.

I've done this when navigating between Retool apps - ie a "you have unsaved changes" prompt - but doing it on the user closing the browser is going to be much more of a challenge as the app is sandboxed and doesn't have access to the parent window or its events.
Might be easier to work with what you have and reconsider what the unload event is trying to prevent

1 Like

Yes you're right, the notification solution was my first idea, I was just exploring other solutions. Anyway thanks for answering!