tough-cookie.cookiejar.setcookie_1.md

July 9, 2025 ยท View on GitHub

Home > tough-cookie > CookieJar > setCookie

CookieJar.setCookie() method

Attempt to set the Cookie in the CookieJar.

Signature:

setCookie(cookie: string | Cookie, url: string | URL, options: SetCookieOptions, callback: Callback<Cookie | undefined>): void;

Parameters

Parameter

Type

Description

cookie

string | Cookie

The cookie object or cookie string to store. A string value will be parsed into a cookie using Cookie.parse().

url

string | URL

The domain to store the cookie with.

options

SetCookieOptions

Configuration settings to use when storing the cookie.

callback

Callback<Cookie | undefined>

A function to call after a cookie has been successfully stored.

Returns:

void

Remarks