Chrome doesn't delete session cookies

2018-12-31 08:43发布

I'm trying to set session cookie in javascript like this:

document.cookie = 'name=alex; path=/'

But Chrome doesn't delete it even if I quit browser and launch it again.

I checked in Firefox and Opera and both work as intended - they delete session cookie on browser exit.

Is Chrome just ignoring expiration rules?

I checked in multiple OSes and found out that session cookie gets removed on Chrome in Windows XP and Ubuntu, but NOT in Mac OSX Lion.

11条回答
不流泪的眼
2楼-- · 2018-12-31 08:51

A simple alternative is to use the new sessionStorage object. Per the comments, if you have 'continue where I left off' checked, sessionStorage will persist between restarts.

查看更多
只若初见
3楼-- · 2018-12-31 08:55

This maybe because Chrome is still running in background after you close the browser. Try to disable this feature by doing following:

  1. Open chrome://settings/
  2. Click "Show advanced settings ..."
  3. Navigate down to System section and disable "Continue running background apps when Google Chrome is closed". This will force Chrome to close completely and then it will delete session cookies.

However, I think Chrome should check and delete previous session cookies at it starting instead of closing.

查看更多
荒废的爱情
4楼-- · 2018-12-31 08:56

Google chrome has a problem if you set and unset cookie improper way. This is php code. Thought this will give you idea.

Set cookie

setcookie('userLoggedIn', 1, 0, PATH);

Wrong way and will not work (notice PATH is missing)

setcookie('userLoggedIn', 0, time()-3600);

Correct way fixes issue on google chrome

setcookie('userLoggedIn', 0, time()-3600, PATH);
查看更多
爱死公子算了
5楼-- · 2018-12-31 09:00

Have you tried to Remove hangouts extension in Google Chrome? because it forces chrome to keep running even you close all the windows.

I was also facing the problem but it resolved now.

查看更多
像晚风撩人
6楼-- · 2018-12-31 09:02

I just had this issue. I noticed that even after I closed my browser i had many chrome processes running. Turns out theses were each from my chrome extension.

Under advanced settings I unchecked 'Continue running background apps when Google Chrome is closed' and my session cookies started working as they should.

Still a pain the the rear for all of us developers that have been coding expecting that session cookies would get cleared when the user is done browsing

查看更多
心情的温度
7楼-- · 2018-12-31 09:04

I had to both, unchecked, under advanced settings of Chrome :

  • 'Continue running background apps when Google Chrome is closed'
  • "Continue where I left off", "On startup"
查看更多
登录 后发表回答