WebPage and WebControls not firing


My Close events appear to never be fired on WebPages and WebControls. The documentation states:
« This can happen when the user closes the browser window or tab containing your web app. You can use this event handler for any cleanup that you need to do when this happens. »
I see no mention of any browser specifics yet nothing is happening:
• Xojo 2019 r1.1 Mac
• Chrome Version 76.0.3809.132 (Official Build) (64-bit) Mac
Repeated Google searches pull up nothing so am I doing something wrong?

Our web app allows users limited annotation of PDF files. We prevent multiple users from accessing the file at the same time. If the user inadvertently closes the browser window or tab, the file is not returned to the file server until the session times out. However we would like to give access to the file sooner if needed.

I was surprised to discover that the session continues to run with the web page and all objects; I had half expected it would just have gone “nil”. So I cannot determine if a file is truly still in edit in this situation.

Or are there better ways for me to be handling this type of situation?


What you are describing sounds like you’re leaking Session objects. The way this typically happens is by having circular references between two or more objects such that none of them ever goes out of scope.

Do you have any properties on your Session which point to webpages or their controls?

Thanks for the quick reply. I do not think so.

I even made a couple of changes to the ListBoxExample project, adding Close events and code to allow me to put a breakpoint to the MainPage and the PeopleList and execution never stops at either. Again, just tested with Chrome Mac.


I will look into this more tomorrow morning!

Thanks again!

Just remember that sessions don’t die immediately. By default they remain for 3 minutes.

Understood. When the session does time out and quits, the Close event is fired, as expected. It’s just that reading in the documentation:
« This can happen when the user closes the browser window or tab containing your web app. You can use this event handler for any cleanup that you need to do when this happens. » lead me to expect that closing the browser window or the tab would lead to the same event firing.

Since all the Xojo code is really running on the Xojo server app, all session code continues to run even if the browser window is no longer displayed to the user. It seems the real question is then “what is a reasonable time lapse for determining the user is no longer active?” Too short a period means I will disconnect people when I should not and frustrate them and too long a period means the file is just not available for someone else (or even the same person just requesting the file again!) as it is still “probably” in use.

Still open to suggestions.

Thanks again for your input!

The good news is that the web framework has a mechanism for this.

Check the docs for Session.Timeout. Setting this value > 0 will make the browser keep track of the last mouse/keyboard event and when one hasn’t happened in the time you specified, Session.TimeOut event will fire. When it does, you can reset the timeout and show a dialog asking if the user is still there. If they don’t respond, log them out and redirect them away from your app to let the Session die off.

Sounds good, I will try this approach! Thank you1

There’s also a way to determine if the web page is visible or not (e.g. the window or tab is not currently being shown): https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API Perhaps this might be an alternative way of checking to see if the user is “active”? It might be neat if the WebSession object had events for this.

The CanIUse for that looks pretty promising too https://caniuse.com/#search=visibilityState
Edit: File it into a feedback ticket to make sure Greg sees it