Javascript delete cookies in browser close even if it is configured to recover cookies on startup

I have a grunt problem that is all over the internet, but I could not find a specific solution to my problem. Here he is:

In Chrome, you have the option "Continue when I stopped" when starting the browser. This, unfortunately, means that all session cookies are stored in the browser, closed and restored or launched in the browser. I need a client-side application (Javascript) to kill a cookie after closing the browser, but this does not happen even if I do not set an expiration date (so that the cookie becomes a session cookie, even Chrome says it expires when the browsing session ends). The problem is that Chrome never kills the browsing session, even if I close the browser or restart the computer due to this darn startup option.

One way is to specify an expiration date of 15 minutes (or something else) in the future. With each user action, the cookie expiration date is updated (recreate the cookie). If the user is inactive for more than 15 minutes (or something else), the cookie dies. I can’t allow 15 minutes to open for another person to open the browser and find myself in the previous session, and I can’t log in to the current user after every time he goes to the toilet. So what I need is exactly this: the user logs in, the cookie is set and saved right before the browser closes. This is the usual session cookie behavior, but ... (previous paragraph).

I also thought about deleting the cookie event when the window () was unloaded, but what if the application is open on several tabs and the user closes only one of them? I could poll the existence of the cookie once per second, and if the cookie was always stored in the Javascript variable, I could restore the cookie (if necessary) once per second if the user closes another tab. This will save the cookie until the last tab with my application is closed, i.e. The browser will not work. This is my best current solution, but I hate it.

Does anyone know of another (cleaner) way to achieve the same? Is there a way to tell Chrome (and / or other browsers) that I don't care about setting up a user launch, my cookie should die in the browser?

Hope I made enough sense :)

thanks

+4
source share
1 answer

The thing is that this is a custom option. This is not an app. Your application has absolutely no business trying to get around it, and you should consider the scenario as if the user was actually in the same session.

+3
source

All Articles