In the past, the Netscape browser was so dominant that many tools emulated its cookie file format. The browser market moved on, but the
cookies.txt file format remains in use by fundamental and popular tools such as curl, wget, and youtube-dl, as well as many others.
Officially, the first line of the file must be one of the following:
# HTTP Cookie File
# Netscape HTTP Cookie File
Fields are separated by tab characters (
Lines are separated by the newline format in use by the running operating system. That means
\r\n) for Windows and
\n) for Unix-like systems such as Linux, macOS, FreeBSD, etc.
The 7 fields are as follows.
|Field Name||Type||Example Value||Notes|
||Hostname that owns the cookie|
||Include subdomains (old attempt at SameSite)|
||Pathname that owns the cookie at the host|
||Send/receive cookie over HTTPS only.|
||Cookie expiration in standard Unix timestamp format|
# HTTP Cookie File example.com FALSE / TRUE 1663611142 cookiename cookievalue example.net FALSE / FALSE 1125326700 cookiename cookievalue example.org TRUE / FALSE 1000210440 cookiename cookievalue example.com FALSE /a/ FALSE 1596693600 cookiename cookievalue
This is a common need so extensions exist for Chrome and Firefox.
It may be useful to extract your own cookies by running a script. This is a small excerpt of a larger script, so it will not run alone as-is. This portion will take a Firefox cookie database, convert it to cookies.txt format, then echo it to
stdout. The work before this snippet plus capturing the output are beyond the scope of this page.
Because of format changes, some data type conversions must be performed during the extract. This is done in the
This snippet of code is not compatible with the Multi-Account Container Extension or the Facebook Container Extension. Multiple cookies that match the same host/path/name tuple might be output. Depending on the website and the way the cookies.txt file is parsed by the tool you're using, you may find inconsistent, unexpected, or contradictory behavior.
- A Bourne-compatible shell with support for here documents, such as
zshto name a few.
- The sqlite3 binary.
echo "# HTTP Cookie File" sqlite3 -separator ' ' "cookies.sqlite" <<- EOF .mode tabs .header off select host, case substr(host,1,1)='.' when 0 then 'FALSE' else 'TRUE' end, path, case isSecure when 0 then 'FALSE' else 'TRUE' end, expiry, name, value from moz_cookies; EOF
Firefox locks the
cookies.sqlite file while running. If you want to run the above script you must either exit Firefox or copy the file to a temporary location.
- The yt-dlp project supports pulling cookies from the browser natively with
--cookies-from-browseras well as the legacy cookies.txt format.