tough-cookie.cookiejar.md

August 1, 2025 ยท View on GitHub

Home > tough-cookie > CookieJar

CookieJar class

A CookieJar is for storage and retrieval of Cookie objects as defined in RFC6265 - Section 5.3.

It also supports a pluggable persistence layer via Store.

Signature:

declare class CookieJar 

Constructors

Constructor

Modifiers

Description

(constructor)(store, options)

Creates a new CookieJar instance.

Properties

Property

Modifiers

Type

Description

prefixSecurity

readonly

string

The configured PrefixSecurityEnum value for the CookieJar.

store

readonly

Store

The configured Store for the CookieJar.

Methods

Method

Modifiers

Description

clone(callback)

Produces a deep clone of this CookieJar. Modifications to the original do not affect the clone, and vice versa.

clone(newStore, callback)

Produces a deep clone of this CookieJar. Modifications to the original do not affect the clone, and vice versa.

clone(newStore)

Produces a deep clone of this CookieJar. Modifications to the original do not affect the clone, and vice versa.

cloneSync(newStore)

Produces a deep clone of this CookieJar. Modifications to the original do not affect the clone, and vice versa.

Note: Only works if both the configured Store and destination Store are synchronous.

deserialize(strOrObj, callback)

static

A new CookieJar is created and the serialized Cookie values are added to the underlying store. Each Cookie is added via store.putCookie(...) in the order in which they appear in the serialization.

deserialize(strOrObj, store, callback)

static

A new CookieJar is created and the serialized Cookie values are added to the underlying store. Each Cookie is added via store.putCookie(...) in the order in which they appear in the serialization.

deserialize(strOrObj, store)

static

A new CookieJar is created and the serialized Cookie values are added to the underlying store. Each Cookie is added via store.putCookie(...) in the order in which they appear in the serialization.

deserializeSync(strOrObj, store)

static

A new CookieJar is created and the serialized Cookie values are added to the underlying store. Each Cookie is added via store.putCookie(...) in the order in which they appear in the serialization.

Note: Only works if the configured Store is also synchronous.

fromJSON(jsonString, store)

static

Alias of CookieJar.deserializeSync().

getCookies(url)

Retrieve the list of cookies that can be sent in a Cookie header for the current URL.

getCookies(url, callback)

Retrieve the list of cookies that can be sent in a Cookie header for the current URL.

getCookies(url, options, callback)

Retrieve the list of cookies that can be sent in a Cookie header for the current URL.

getCookies(url, options)

Retrieve the list of cookies that can be sent in a Cookie header for the current URL.

getCookiesSync(url, options)

Synchronously retrieve the list of cookies that can be sent in a Cookie header for the current URL.

Note: Only works if the configured Store is also synchronous.

getCookieString(url, options, callback)

Accepts the same options as .getCookies() but returns a string suitable for a Cookie header rather than an Array.

getCookieString(url, callback)

Accepts the same options as .getCookies() but returns a string suitable for a Cookie header rather than an Array.

getCookieString(url, options)

Accepts the same options as .getCookies() but returns a string suitable for a Cookie header rather than an Array.

getCookieStringSync(url, options)

Synchronous version of .getCookieString(). Accepts the same options as .getCookies() but returns a string suitable for a Cookie header rather than an Array.

Note: Only works if the configured Store is also synchronous.

getSetCookieStrings(url, callback)

Returns an array of strings suitable for Set-Cookie headers. Accepts the same options as .getCookies().

getSetCookieStrings(url, options, callback)

Returns an array of strings suitable for Set-Cookie headers. Accepts the same options as .getCookies().

getSetCookieStrings(url, options)

Returns an array of strings suitable for Set-Cookie headers. Accepts the same options as .getCookies().

getSetCookieStringsSync(url, options)

Synchronous version of .getSetCookieStrings(). Returns an array of strings suitable for Set-Cookie headers. Accepts the same options as .getCookies().

Note: Only works if the configured Store is also synchronous.

removeAllCookies(callback)

Removes all cookies from the CookieJar.

removeAllCookies()

Removes all cookies from the CookieJar.

removeAllCookiesSync()

Removes all cookies from the CookieJar.

Note: Only works if the configured Store is also synchronous.

serialize(callback)

Serialize the CookieJar if the underlying store supports .getAllCookies.

serialize()

Serialize the CookieJar if the underlying store supports .getAllCookies.

serializeSync()

Serialize the CookieJar if the underlying store supports .getAllCookies.

Note: Only works if the configured Store is also synchronous.

setCookie(cookie, url, callback)

Attempt to set the Cookie in the CookieJar.

setCookie(cookie, url, options, callback)

Attempt to set the Cookie in the CookieJar.

setCookie(cookie, url, options)

Attempt to set the Cookie in the CookieJar.

setCookieSync(cookie, url, options)

Synchronously attempt to set the Cookie in the CookieJar.

Note: Only works if the configured Store is also synchronous.

toJSON()

Alias of CookieJar.serializeSync(). Allows the cookie to be serialized with JSON.stringify(cookieJar).