Ensure localstorage clear just before Application.Exit() ?

Answered
0
0

Hi
Some advice to clear localstorage just before call Application.Exit(); ? It doesn’t work

Application.Browser.LocalStorage.Clear();
Application.Exit();

Thanks in advance!

  • You must to post comments
Best Answer
0
0

Hi,

The behaviour you describe is “by design” – out-of-bounds events raised just before calling Application.Exit() aren’t executed.

Clearing the local storage is an out-of-bounds event, meaning it’s executed asynchronously, after other actions are done. In this case, other actions means Application.Exit(). So by the time Wisej is supposed to clear the local storage, there is no session any longer, so there is nothing for Wisej to do.

Since clearing the local storage is an out-of-bounds event, we can use Application.Update() on a Page or Form. Plesae give this a try

Application.Update(this, () => {
    Application.Browser.LocalStorage.Clear();
});
Application.Exit();

 

Another approach is to execute code in the browser when Application.Exit() is called on the server. Please refer to this thread.

Nevertheless, using session storage is the best approach for temporary storage of information you don’t want to be persistent after the browser/tab is closed.

 

  • Ser Gar
    This advice working as expected. Thanks
  • You must to post comments
0
0

Some workaround to this?

Application.Update(this, () => {
Application.Browser.LocalStorage.Clear();
});
Application.Exit();

it worked fine with the wisej 1x, but doesnt work as expected with the wisej 2x
Thanks in advance

  • You must to post comments
0
0

I want to use localstorage because i want to it to be persistent.
I have a hybrid android app (webview) that points to my url, when I close and reopen the app or restart the phone, I restore the state through localstorage.
I will try your advice, i had to use a timer to have a Application.Exit() after localstorage clear
Thanks

  • Luca (ITG)
    There is no event that is fired when the browser is closed, or the tab is closed. Clearing local storage when the session is disposed is a guess at best.
  • You must to post comments
0
0

Hi,

Thank you for your report. We are investigating the issue.

In the mean time, since you want to clear the browser storage when a session ends, maybe you should try SessionStorage. Session storage is per tab and it goes away when you close the tab and, of course, when you close the browser. This behaviour of SessionStorage is defined by the W3C Recommendation and is the browser’s responsibility

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.