A Netscape cookie file is the oldest portable form a cookie has. Netscape invented it so cookies would survive a browser restart, curl adopted it to share cookies with browsers, and then, in curl's own words, the browsers moved away from it: "Modern browsers no longer use it, while curl still does" (curl docs). It lives on because command-line tools read it. When yt-dlp, curl or a scraper asks for cookies.txt, this is the format it means.

What a cookies.txt file looks like

Here is a three-cookie file. The gaps between columns are single tab characters.

# Netscape HTTP Cookie File

.example.com	TRUE	/	TRUE	1798761600	theme	dark
#HttpOnly_.example.com	TRUE	/	TRUE	1798761600	sessionid	8f2c1e9a
shop.example.com	FALSE	/cart	FALSE	0	cart	3

Lines that start with # are comments and blank lines are ignored. The first line is a comment too, but some readers insist on it: yt-dlp requires the first line to be # HTTP Cookie File or # Netscape HTTP Cookie File (yt-dlp FAQ). When we fed that file to curl 8.7.1 with -b cookies.txt -c out.txt, curl wrote it back with its own header, # This file was generated by libcurl! Edit at your own risk., and the same three cookies.

Every cookie line has seven fields, in this order. The names and examples follow curl's documentation of the format.

#FieldExampleWhat it means
1Domain.example.comThe host the cookie belongs to
2Include subdomainsTRUETRUE sends it to every subdomain too; FALSE to that exact host only
3Path/The cookie is sent only for URLs under this path
4SecureTRUETRUE means HTTPS only
5Expires1798761600Seconds since 1 January 1970; 0 means a session cookie
6NamethemeThe cookie's name
7ValuedarkThe cookie's value, the last thing on the line

1798761600 is midnight UTC on 1 January 2027. Fields 2 and 4 are written in capitals by convention, and most readers compare them without caring about case.

Fields 1 and 2 describe the same thing twice, and they should agree. A domain written with a leading dot goes with TRUE in field 2; a bare host such as shop.example.com goes with FALSE. Cookie-Editor's reader takes its host-only flag from field 2 alone (Cookie-Editor source), so a file where the two disagree imports as whatever field 2 says.

Bring a logged-in session in, take it out, keep it sealedIn Mosaic: Cookie jars. Import, export and keep cookies, encrypted on disk. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

How it works: Cookie jars

The #HttpOnly_ prefix

HttpOnly is not a column. A cookie with the HttpOnly attribute is written with #HttpOnly_ stuck to the front of its domain, as on the second line of the example. curl's documentation calls it the one exception to the comment rule: "Lines that start with # are treated as comments. An exception is lines that start with #HttpOnly_".

Hand-written parsers go wrong here, and it costs them the most important cookies. Session tokens are the cookies sites mark HttpOnly, so a reader that skips every line starting with # imports the theme preference and the cart and drops the login. If an import "worked" and you are still signed out, look for #HttpOnly_ lines first.

What the format cannot hold

The format was fixed long before several cookie attributes existed, so a conversion to Netscape loses them:

  • SameSite: Chrome's cookie API stores Strict, Lax or None for each cookie (chrome.cookies); a cookies.txt line has nowhere to put it.
  • The partition key and the priority, both columns in Chrome DevTools' cookie table (DevTools docs).
  • In practice, whether a session cookie is a session cookie. The format allows 0, but Cookie-Editor's exporter writes session cookies with an expiry one day ahead, with a comment explaining that this stops them being discarded when imported back. A cookie exported that way stops working the next day.

That is why we suggest JSON for moving a session from one browser to another, and Netscape only when the tool at the other end needs it.

Tabs, spaces and line endings

The fields are separated by tab characters, and that is the most common reason a cookies.txt file is rejected. A file pasted through a chat window or a web form often arrives with spaces instead of tabs. Cookie-Editor splits each line on tabs and rejects any line that does not come out as exactly seven fields. Line endings matter to yt-dlp as well: its FAQ asks for CRLF on Windows and LF on macOS and Linux, and says an HTTP Error 400: Bad Request when using --cookies is "a good sign of invalid newline format".

Converting cookies.txt to JSON

Browser extensions and most automation tools want JSON. This Python script turns a cookies.txt into the JSON array Cookie-Editor exports, with the same key names Chrome's cookie API uses. It assumes real tabs, as the format does.

import json, sys

cookies = []
for line in open(sys.argv[1], encoding="utf-8"):
    line = line.rstrip("\r\n")
    http_only = line.startswith("#HttpOnly_")
    if http_only:
        line = line[len("#HttpOnly_"):]
    if not line.strip() or line.startswith("#"):
        continue
    domain, subdomains, path, secure, expires, name, value = line.split("\t")
    cookie = {
        "domain": domain,
        "hostOnly": subdomains.upper() != "TRUE",
        "path": path,
        "secure": secure.upper() == "TRUE",
        "httpOnly": http_only,
        "name": name,
        "value": value,
    }
    if int(expires) == 0:
        cookie["session"] = True
    else:
        cookie["expirationDate"] = int(expires)
    cookies.append(cookie)

print(json.dumps(cookies, indent=2))

Run it as python3 cookies_to_json.py cookies.txt > cookies.json. On the example file it prints three cookies, with "httpOnly": true on sessionid and "session": true on cart. A line with the wrong number of fields stops it with a ValueError, which is what you want: a converter that skips bad lines quietly hands you a session with a hole in it.

How Mosaic reads cookies.txt

A Mosaic profile's Cookies tab takes a Netscape file as it is, alongside JSON and a pasted Cookie header, and we wrote its reader around the failures above. It splits a line on any run of whitespace, so the tabs-turned-to-spaces file loads; we checked that the example above gives the same three cookies either way. It keeps #HttpOnly_ lines as HttpOnly cookies. It treats the rest of the line after the name as the value. And a line it cannot read is reported by number, as "Line 6 is not a Netscape cookie row", instead of being dropped.

Mosaic reads cookies.txt but does not write it: Export current gives the profile's jar as JSON. Where those exports come from and go to in Chrome is in how to export cookies from Chrome and how to import cookies into Chrome; carrying a whole signed-in session across is moving a logged-in session to another browser. Scripts that load cookies into many profiles at once use the local API, covered in automating multiple browser profiles.