Getting All Cookies From A Website Using Developer Console

raunit - in Others
Learn to retrieve all cookies from a website effortlessly with the Developer Console. Follow our comprehensive guide for clear, actionable steps and tips.
const cookies = document.cookie.split("; ").reduce((acc, cookie) => {
    const [name, ...value] = cookie.split("=");
    acc[name] = value.join("=");
    return acc;
}, {});

// Convert to JSON string
const cookieJSON = JSON.stringify(cookies);
console.log(cookieJSON)
Sample Output:
{
  "PREF": "f4=4000000&f6=daad&tz=Asia.Calcut=true&volume=30",
  "APISID": "qDkiEKVTRMTSek/A9pdlnZgPBB-0E1JY",
  "SAPISID": "wmOsZzkpv9Wiv_T5/APAWMjZDedpMMD",
  "__Secure-1PAPISID": "wmOsZzkpv9Wiv_T5/APAMjZDedpMMD",
  "__Secure-3PAPISID": "wmOsZzkpv9Wiv_T5/APJWMjZDedpMMD",
  "SID": "g.a000rgidyLx---XD9EALDQVZ3Kha_16l76",
  "SIDCC": "-nEaZdwo_LjOstx3_d9h"
}
Code:
const cookies = document.cookie.split("; ").map((cookie) => {
    const [name, ...valueParts] = cookie.split("=");
    const value = valueParts.join("=");

    return {
        name,
        value,
        domain: window.location.hostname, // Default to the current domain
        path: "/", // Default path
        secure: location.protocol === "https:", // Secure if using HTTPS
        httpOnly: false, // Cannot be determined directly in JavaScript
        sameSite: "Lax", // Default SameSite policy
        hostOnly: true, // Assumed as true for simplicity
        expirationDate: null // Requires server-set expiration (optional)
    };
});

const cookieJSON = JSON.stringify(cookies);
console.log(cookieJSON);
Output:
[
  {
    "name": "PREF",
    "value": "f4=4000000&f6autoplay=true&volume=30",
    "domain": "www.youtube.com",
    "path": "/",
    "secure": true,
    "httpOnly": false,
    "sameSite": "Lax",
    "hostOnly": true,
    "expirationDate": null
  },
  {
    "name": "APISID",
    "value": "qDkiEKVTRMTSeklm/-0E1JY",
    "domain": "www.youtube.com",
    "path": "/",
    "secure": true,
    "httpOnly": false,
    "sameSite": "Lax",
    "hostOnly": true,
    "expirationDate": null
  }
]
You can change the other values like domain, path, secure etc by looking at the cookies in the browser console.

Handling HttpOnly Cookies

Cookies with the HttpOnly attribute cannot be accessed using JavaScript. To modify such cookies:

  • Open the Developer Tools and navigate to the Application tab.
  • Under the Storage section, select Cookies and choose the domain for the website.
  • Find the cookie marked with HttpOnly and uncheck the box next to it to disable the attribute temporarily.
  • Refresh the page or make changes as required. Note that this may not work if the server enforces strict HttpOnly rules.
Tagschromecookiesextract cookiescookies to json
raunit-picture
raunit

Technical Writer at CodingKaro

Share this on
Other Blogs in Others