How to Debug JavaScript Cookie Disappearance Issue in Web App?

894359 used Ask the Experts™
I'm trying to figure out how to debug a JavaScript cookie disappearance issue? I have some code that sets a cookie on one page and then reads the cookie on the next page. This code has worked for years. I'm now having some issues with specific pages only. I put console.logs for the cookie setting and reading. The cookie is always set with the value but on specific pages, the value is missing when the next page loads which is supposed to read the cookie value. I'm not sure how to debug this issue? Somewhere between the cookie being set and the cookie being read on the next page, it is  being deleted. It doesn't help to watch the cookie in the application section of Chrome as I can see the cookie is created via the console.logs. How do I debug if/how this cookie is being deleted by the web app in between the page unload and load of the next page?  

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Use the debug mode of your browser and look at the headers. (For firefox that would be pressing F12 and the clicking on network)

At the page, that sets the cookie you should see cookie headers in the response headers.

at the page following you should see the cookie in the request header.

There might be many reasons why the cookies are not working, but the cookie header in the response, the url of the seubsequent request and it's headers might give you that information.

If you mean cookies, that are set by javascript, then you woud have no response header with a cookie header, but you should see cookie headers in the subsequent requests.

You might also check the CSP headers provided by the web server and show them here.
Other questions:
Did the web server change?
Did the hostname change?

Could you provide a test case (a simplified version of your javascript) showing that cookies don't work anymore?


Hi Gelonida,
No the web server and host name didn't change.  My code won't help because it is from a Tag Management System (Adobe DTM).  I've tried some testing and it doesn't matter which cookie is created (cookie name I was debugging is 'navElemName') , they are all somehow deleted by the web app. I've even tested where I create another cookie ( “navElemNameNotDeletedDuplicate” )  that has no code to delete it or interact with it in any way and that disappears also. I just need to figure out why? You can see this in action. I have 3 steps tracked by console.logs which start with “COOKIE TEST” which you should see when clicking any of the green “APPLY NOW” buttons. If you go to this page below, you’ll see it works as designed.

But if you go to this page and click on a green “APPLY NOW” button:

You’ll notice the cookie gets deleted before the next page can read it.

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Is there any way to have one setup of your web page, that was still working and one setup that is broken?

Then you might look at all the differences that happen between the two setups.

Probably not helpful, but just to be sure:
Did you try with different browsers? Firefox / Chrome.

Were the versions of your browsers updated recently. If yes do you still have access to a previous version?

Did  you update the version Adobe DTM or any other javascript framework?


HI, The code is the same for the working URL and broken URL I provided. One thing to clarify is that you won't see a cookie value set until after you click on the "APPLY NOW" buttons and go to the subsequent page.

Shows example of output on subsequent page for working version.

I had to use session storage instead of cookies. For some reason the cookie wasn't being written at times but the session storage worked 100%?
glad you found a solution.

Sorry that I couldn't help more


Thank you Gelonida! Much appreciated!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial