-
-
Notifications
You must be signed in to change notification settings - Fork 227
CookieContainer
David Ortner edited this page Apr 10, 2025
·
10 revisions
CookieContainer represents a container for cookies stored in memory in the BrowserContext.
class CookieContainer implements ICookieContainer
Method | Return type | Description |
---|---|---|
addCookies() | void | Adds cookies. |
getCookies() | ICookie[] | Returns cookies. |
import { Browser, CookieSameSiteEnum } from "happy-dom";
const browser = new Browser();
browser.defaultContext.cookieContainer.addCookies([
{
key: "key1",
originURL: "https://example.com",
},
{
key: "key2",
originURL: "https://example.com",
value: "value2",
domain: "example.com",
path: "/path/to/page/",
expires,
httpOnly: true,
secure: true,
sameSite: CookieSameSiteEnum.strict,
}
]);
// Outputs:
// [
// {
// key: "key2",
// originURL: "https://example.com",
// value: "value2",
// domain: "example.com",
// path: "/path/to/page/",
// expires,
// httpOnly: true,
// secure: true,
// sameSite: "Strict"
// }
// ];
console.log(
browser.defaultContext.cookieContainer.getCookies(
"https://example.com",
true
)
);
Help Packages