In order to sync local data with server, it would be useful to have an event that is triggered when the user leaves / closes a website. It is already possible to detect when a user leaves a page using the Page Visibility API, however it is not possible to detect the end of session (e.g. expiration of sessionStorage).
This event would allow developers to save data changes locally and collect website analytics (e.g. performance, tracking, user preferences) inside sessionStorage (or localStorage) and then send the data to the server only once, at the end of the visit, instead of creating an additional HTTP request for each page view.
What exactly is the use-case you’re trying to achieve here? In general these techs exist for their intended goals and they work very well.
You also don’t need to send a request for each page view using local storage. You can send a request to update the server data only when a value is modified. That means regardless of when/how it happens, if the value changes the server will know. No need to handle it in a session ending event.