Netscape cookies.txt

In the past, the Netscape browser was so dominant that many tools emulated its cookie file format. The browser market moved on, but the  file format remains in use by fundamental and popular tools such as curl, wget, and youtube-dl, as well as many others.

File format
Officially, the first line of the file must be one of the following:

Fields are separated by tab characters ( or   or  ).

Lines are separated by the newline format in use by the running operating system. That means   for Windows and    for Unix-like systems such as Linux, macOS, FreeBSD, etc.

The 7 fields are as follows.

Example 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
 * 1) HTTP Cookie File

Extract cookies to Netscape cookies.txt format
This is a common need so extensions exist for Chrome and Firefox.
 * Chrome - Get cookies.txt
 * Firefox - cookies.txt

Code snippet to extract cookies from Mozilla Firefox to Netscape cookies.txt format
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. 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  statements.

'''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.'''

Prerequisites:
 * A Bourne-compatible shell with support for here documents, such as,  ,  ,  ,  , and   to 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  file while running. If you want to run the above script you must either exit Firefox or copy the file to a temporary location.

Links

 * cURL cookie file format