async function setTestCookies() {
// Set two cookies
try {
await cookieStore.set("cookie1", "cookie1-value");
} catch (error) {
console.log(`Error setting cookie1: ${error}`);
}
try {
await cookieStore.set("cookie2", "cookie2-value");
} catch (error) {
console.log(`Error setting cookie2: ${error}`);
}
}CookieStore: getAll() method / notebook
CookieStore: getAll() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
async function cookieTest() {
// Set our test cookies
await setTestCookies();
// Get all cookies
const cookies = await cookieStore.getAll();
// Iterate the cookies, or log that none were found
if (cookies.length > 0) {
console.log(`Found cookies: ${cookies.length}:`);
cookies.forEach((cookie) => console.log(cookie));
} else {
console.log("Cookies not found");
}
}