Skip to content

Replace deprecated 'unload' with modern 'pagehide' event listener#2130

Open
bschwarzent wants to merge 1 commit intoreleases/24.2from
features/bsh/24.2/454776_unload_pagehide
Open

Replace deprecated 'unload' with modern 'pagehide' event listener#2130
bschwarzent wants to merge 1 commit intoreleases/24.2from
features/bsh/24.2/454776_unload_pagehide

Conversation

@bschwarzent
Copy link
Copy Markdown
Member

When the user leaves the current page (either because they close the tab or navigate away) or just simply reloads the page, the UI session should be disposed. Otherwise, UI sessions might accumulate if the HTTP session itself is still in use. To notify the UI server about a disposed UI session, a window listener for the 'unload' event was used.

Recently, some browsers have declared the 'unload' event to be obsolete and started to ignore it by default [1]. To make sure UI sessions are still disposed on the UI server when no longer in use, the event listeners have to changed to the more modern 'pagehide' event. However, using this event can under some circumstances enable the browser's back/forward cache [2]. This would store and restore the previous state of a page for a faster user experience. Since this can potentially cause problems for Scout Classic applications, we simply reload the page when being restored from the bfcache to make sure the state in the browser is up-to-date.

Some old Jasmine contained a call to a special JasmineScout method uninstallUnloadHandlers(). This method has not been necessary or useful for several years. Therefore, it was removed.

[1] https://developer.chrome.com/docs/web-platform/deprecating-unload
[2] https://web.dev/articles/bfcache

454776

When the user leaves the current page (either because they close the tab
or navigate away) or just simply reloads the page, the UI session should
be disposed. Otherwise, UI sessions might accumulate if the HTTP session
itself is still in use. To notify the UI server about a disposed UI
session, a window listener for the 'unload' event was used.

Recently, some browsers have declared the 'unload' event to be
obsolete and started to ignore it by default [1]. To make sure UI
sessions are still disposed on the UI server when no longer in use,
the event listeners have to changed to the more modern 'pagehide'
event. However, using this event can under some circumstances enable
the browser's back/forward cache [2]. This would store and restore the
previous state of a page for a faster user experience. Since this can
potentially cause problems for Scout Classic applications, we simply
reload the page when being restored from the bfcache to make sure the
state in the browser is up-to-date.

Some old Jasmine contained a call to a special JasmineScout method
uninstallUnloadHandlers(). This method has not been necessary or useful
for several years. Therefore, it was removed.

[1] https://developer.chrome.com/docs/web-platform/deprecating-unload
[2] https://web.dev/articles/bfcache

454776
@bschwarzent bschwarzent requested a review from cguglielmo April 2, 2026 13:27
@bschwarzent bschwarzent self-assigned this Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant