Chrome doesn't delete session cookies - javascript

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.

This can be caused by having Chrome set to Continue where you left off.
Further reading
Bug report: Chrome is not deleting temporary cookies – i.e. not logging me out automatically when I close all browser Windows
Issue 128513 in Chromium: Session Cookies not cleared when Chrome processes closed
Issue 128567: Session only cookies don't delete

I just had the same problem with a cookie which was set to expire on "Browsing session end".
Unfortunately it did not so I played a bit with the settings of the browser.
Turned out that the feature that remembers the opened tabs when the browser is closed was the root of the problem. (The feature is named "On startup" - "Continue where I left off". At least on the current version of Chrome).
This also happens with Opera and Firefox.

I just had this issue.
I noticed that even after I closed my browser I had many Chrome processes running. Turns out these 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 in the rear for all of us developers that have been coding expecting that session cookies would get cleared when the user is done browsing.

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"

This maybe because Chrome is still running in background after you close the browser. Try to disable this feature by doing following:
Open chrome://settings/
Click "Show advanced settings ..."
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.

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.

This issue is caused because you are using Continue where I left off and Continue running background apps when Google Chrome is closed feature of chrome (currently my version is 96).
Please consider setting those off (to test functionality).

I had the same problem with "document.cookie" in Windows 8.1, the only way that Chrome deletes the cookie was shutting it from task manager (not a really fancy way), so I decided to manage the cookies from the backend or use something like "js-cookie".

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.

Go to chrome://settings/content/cookies?search=cookies
Enable Clear cookies and site data when you quit Chrome.
Worked for me

If you set the domain for the php session cookie, browsers seem to hold on to it for 30 seconds or so. It doesn't seem to matter if you close the tab or browser window.
So if you are managing sessions using something like the following it may be causing the cookie to hang in the browser for longer than expected.
ini_set("session.cookie_domain", 'www.domain.com');
The only way I've found to get rid of the hanging cookie is to remove the line of code that sets the session cookie's domain. Also watch out for session_set_cookie_params() function. Dot prefixing the domain seems to have no bearing on the issue either.
This might be a php bug as php sends a session cookie (i.e. PHPSESSID=b855ed53d007a42a1d0d798d958e42c9) in the header after the session has been destroyed. Or it might be a server propagation issue but I don't thinks so since my test were on a private servers.

I just had this problem of Chrome storing a Session ID but I do not like the idea of disabling the option to continue where I left off. I looked at the cookies for the website and found a Session ID cookie for the login page. Deleting that did not correct my problem. I search for the domain and found there was another Session ID cookie on the domain. Deleting both Session ID cookies manually fixed the problem and I did not close and reopen the browser which could have restored the cookies.

The solution would be to use sessionStorage, FYI: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

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);

Related

JS: Chrome extension setting cookies

I'm using a Chrome extension to help me work on a webpage but it's setting cookies from doubleclick.net even though I've disabled third party cookies in the Chrome settings. It's annoying because they're filling up my console with messages.
They're not appearing in document.cookie so is there any way to delete them in JavaScript? Or some other way to stop them being set?
I personally the use EditThisCookie extension for chrome when developing web apps using cookies. It allows creation, editing, deleting and most importantly for you blocking of cookies.
You can block a domain from setting a cookie by:
1. Select the cookie from the menu and click block.
2. This opens a menu where you can set a rule blocking the domain from creating new cookies.

How to get Chrome to stop asking me whether its ok to use the camera?

I am doing some html/js/webrtc work with the webcam. Even though I am hosting files from the web server on my machine (thus 127.0.0.1), Chrome asks me whether its ok to use the camera every time I reload the page.
How can I get it to stop?
Just activate chrome://flags/#allow-insecure-localhost. This will work like https and fix a lot of development problems, including invalid ssl certificates.
use https. Chrome does not persist permissions on http and getUserMedia will stop working there soon (even though possibly not on localhost).
Alternatively, use command line flags like --use-fake-ui-for-media-stream to skip this.

localStorage on IE8 / IE9 with localhost or LAN server name doesn't work

I'm using https://github.com/jarednova/jquery-total-storage to access localStorage. In IE8 and IE9, I'm having a weird issue and it seems to occur even if I just use plain old javascript.
If I go to http://foo and use $.totalStorage, it persists through that session but is gone when I close and open IE.
If I go to http://foo.mydomain.com and use $.totalStorage, it persists when I close and open IE.
It even occurs when I launch (localhost) debugging from Visual Studio!
In Firefox / Chrome, it persists between sessions regardless of if I got go foo or foo.mydomain.com
Is this a known issue? Is there a workaround?
UPDATE: To reproduce this, just add this script block to your page, then serve it from http://localhost or http://yourpcname:
<script>
var storage = window.localStorage;
alert (storage.foo);
storage.foo = 'bar!';
</script>
The first time you run it on localhost you'll get "undefined". Then if you refresh you'll get "bar!". Then if you close out of IE and go back in again, you'll get "undefined" instead of "bar!".
Sound's like your creating a express IIS or "visual studio development server" every time you launch the debugger.
If you host your web application without creating a express instance every debug, and setting up a permanent application though IIS, this shouldn't happen.

Firefox session not deleting automatically

I'm running Linux Mint and using Firefox 3.6.10. I'm setting a cookie using jQuery
$.cookie("ws", "1") ;
This cookie will expires At end of session. But when I close the browser. This session is not expiring automatically. Could you guys help me?
I had similar problem. It happens when you set up your browser to remember opened tabs. In this case firefox does not delete session cookies, since the session didn't ended, and will continue when browser is opened again

Proxy settings in Firefox don't "stick"

At home we have a proxy server. At work we don't. Firefox irritates in this regard: whenever I launch it, it defaults to the proxy server. If I do Tools>Options>Settings and select "No proxy", no problem. However, if I shutdown Firefox and restart it, I have to do the Tools>Options>Settings thing all over again because the "No proxy" setting doesn't "stick".
How do I make it stick? Alternatively, can someone suggest a bit of javascript that I can assign to a button on my toolbar which will toggle between the two states?
Use FoxyProxy, much more flexible to configure
The problem was a recent windows-only regression in Firefox.
It was hard to track down, basically I got lucky...
Here's the meta bug:
https://bugzilla.mozilla.org/show_bug.cgi?id=448634
Here's where the fix was put in.
https://bugzilla.mozilla.org/show_bug.cgi?id=446536
I haven't had time to verify it, my windows system is dead right now, so I have to do it via bugmail.
I used a local automatic proxy configuration script for years with great success. The trick was identifying from the URL or IP address where I was.
/Allan

Categories