on 2023 Dec 13 3:37 PM
For accomplishing business requirement, we need to catch when end user closes his session, meaning: when he navigate to another external url; closes window/tab; closes browser itself. Logout and timeout are already handled properly
As per my findings, "onbeforeunload" function is already used by SAPUI5 library, so either I replace it with my one or find another solution
Many thanks
Massimiliano
Request clarification before answering.
Neither `unload` nor `beforeunload` should be used as an end-of-session signal. The former one is deprecated and the `beforeunload` is applicable only for notifying the user about unsaved changes. I'd suggest implementing handlers based on the guidelines Page Lifecycle API | Web Platform | Chrome for Developers especially the diagram from the section "Overview of Page Lifecycle states and events".
When sending an end-of-session signal, the request should not be based on XMLHttpRequest (XHR). The HTML specification doesn't guarantee that XHRs are sent reliably in a page dismissal or visibility change event. The replacement for XHR in such events is the Beacon API:
> "[...] Unlike requests made using XMLHttpRequest [...], the browser guarantees to initiate beacon requests before the page is unloaded and to run them to completion."
Note that `navigator.sendBeacon` doesn't support anything other than POST, and requires the payload not to exceed 64 kB. In case more configuration on such requests is required, `fetch` API with the option `keepalive: true` should be used.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi Boghyon, thanks for suggestions - I've already read and tried what mentioned under both links; point is that not all "end-of-session" events are handled, as an example: if end user changes URL this navigation outside application is not catch. Window/tab closure works, refresh event works - as per my tests, only "beforeunload" is triggered when URL is changed by end user.
Thanks
Massimiliano
User | Count |
---|---|
53 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.