3 min read

Convert Selenium get_cookies() JSON to a cookie file

Selenium get_cookies() returns a JSON list of dicts with expiry (not expirationDate); paste that list here to normalise it for CookieMan Import or Netscape cookies.txt.

This is for fixtures and debugging your own tests. It is not a way to pull someone else’s session out of a remote WebDriver.

Selenium cookiesget_cookies JSONSelenium to cookies.txtWebDriver cookies
  1. 1
    Dump cookies from WebDriver

    In Python, json.dumps(driver.get_cookies()). In Java, serialize driver.manage().getCookies() to a JSON array of objects with name, value, domain, path, expiry.

  2. 2
    Normalise in the converter

    Paste the array. expiry maps to expirationDate. Values <= 0 become session cookies. Output JSON Array for Chrome, or switch to Netscape for curl.

  3. 3
    Add them back or send from curl

    CookieMan Import on the test origin, or driver.add_cookie() with the JSON objects, or curl -b cookies.txt after a Netscape export.

Cookies are credentials. Conversion stays in this page — delete the file when you are done.

Selenium field names this parser accepts

Selenium / WebDriverCookieMan JSONNotes
name / valuesameRequired
domaindomainKeep the leading dot if present
pathpathDefaults to /
secure / httpOnlysameBooleans
expiry or expiresexpirationDateSeconds; <= 0 → session
sameSitesameSiteLax/Strict/None fold to lowercase enums
Millisecond timestamps (> 1e12) are divided by 1000. That matches how some Java bindings leak Date.getTime() into expiry.
            import json
from pathlib import Path

# after converting to JSON Array in the tool:
cookies = json.loads(Path("cookies.json").read_text())
for cookie in cookies:
    # Selenium rejects 'expiry' on session cookies — drop it
    cookie.pop("hostOnly", None)
    cookie.pop("session", None)
    if cookie.get("expirationDate"):
        cookie["expiry"] = cookie.pop("expirationDate")
    else:
        cookie.pop("expirationDate", None)
    driver.add_cookie(cookie)
          

Questions people ask

Why does add_cookie fail after import?
You must be on a matching origin first. __Host- names still need Secure, Path=/ and no Domain. SameSite=None still needs Secure. The converter does not relax Chrome’s rules.
Does get_cookies include HttpOnly cookies?
Yes. WebDriver reads the browser store, not document.cookie. Keep httpOnly when you convert; Netscape will emit #HttpOnly_.
How is this different from Playwright storageState?
Playwright wraps cookies in { "cookies": [...], "origins": [] } and uses expires: -1 for session cookies. That wrapper is unwrapped automatically — see Playwright storageState to cookies.txt.
3 min read

Playwright storageState to cookies.txt

Paste a Playwright storageState file. The converter unwraps the cookies array, treats expires -1 as a session cookie, and writes Netscape for curl or Chrome JSON.

Playwright storageStatePlaywright cookies.txt Open the guide
3 min read

Puppeteer Cookies JSON to cookies.txt

Paste the array from page.cookies() or browser.cookies() and convert it to Netscape or CookieMan JSON. expires -1 is a session cookie; SameSite is kept only in JSON.

Puppeteer cookiespage.cookies JSON Open the guide
3 min read

JSON Array vs cookies.txt Field Mapping

Side-by-side mapping of CookieMan JSON Array fields to Netscape cookies.txt. SameSite, partitionKey and store metadata never survive the seven-column file.

JSON vs cookies.txtcookies.txt field mapping Open the guide

Apply this on live cookies

The converter rewrites files. The extension reads and writes the jar in Chrome, including HttpOnly cookies.

Free and MIT-licensed · Chrome, Edge and other Chromium browsers · Nothing leaves your machine