Backbencher.dev

SOLVED: Unable To Read Cookie Using JavaScript

Last updated on 28 Jun, 2022

In JavaScript we can create, read or update the value of cookie using document.cookie. Below code prints all the cookies of the site separated by semi-colon.

console.log(document.cookie);

But, a cookie that is set as HttpOnly will not be there in the list. The server that sends the HTTP response decides if a cookie needs to be HttpOnly or not, by adding the attribute to the end of Set-Cookie header.

Set-Cookie: <name>=<value>[; <Max-Age>=<age>]
[; expires=<date>][; domain=<domain_name>]
[; path=<some_path>][; secure][; HttpOnly]

So if you find a working cookie code failing suddenly, this can be the reason. Check with the backend team if they had done any changes.

In Chrome, a HttpOnly cookie is marked with a tick mark in the cookies list.

HTTP Only
--- ○ ---
Joby Joseph
Web Architect