Modern Cookies, Minus the Mess: A Quick Guide to the Cookie Store API

Collection of half chocolate chip cookies on white background

If you’ve ever wrangled document.cookie, you know it’s a synchronous string mess that’s easy to misuse and hard to reason about. The Cookie Store API modernizes cookies with a promise-based, structured interface that works in window and service worker contexts. It enables async reads/writes, typed cookie objects, and change events—perfect for performance-sensitive and offline-capable apps.

What it looks like

Set a cookie asynchronously

				
					cookieStore.set({ name, value, expires, path, sameSite });
				
			

Returns a promise; no string parsing needed.

 Read a cookie

				
					cookieStore.get(name);
				
			

Resolves to a cookie object or null.

 List cookies

				
					cookieStore.getAll();
				
			

Returns an array of cookie objects.

Delete a cookie

				
					cookieStore.delete(name);
				
			

Removes it by key.

Listen for changes

				
					cookieStore.addEventListener('change', handler);
				
			

Fires when cookies are changed or deleted—even across tabs (where supported).

Walking through the demo

				
					// 1. Set a cookie asynchronously
const setCookie = async () => {
	await cookieStore.set({
		name: 'demoCookie',
		value: 'cookieStoreRocks',
		expires: Date.now() + 60 * 60 * 1000, // 1 hour from now
		path: '/',
		sameSite: 'lax'
	});
	console.log('Cookie set!');
};

// 2. Get a cookie by name
const getCookie = async () => {
	const cookie = await cookieStore.get('demoCookie');
	if (cookie) {
		console.log('Cookie value:', cookie.value);
	} else {
		console.log('Cookie not found.');
	}
};

// 3. List all cookies
const listCookies = async () => {
	const cookies = await cookieStore.getAll();
	console.log('All cookies:', cookies);
};

// 4. Delete a cookie
const deleteCookie = async () => {
	await cookieStore.delete('demoCookie');
	console.log('Cookie deleted!');
};

// 5. Listen for cookie changes (works in supported browsers)
cookieStore.addEventListener('change', (event) => {
	for (const changed of event.changed) {
		console.log('Cookie changed:', changed);
	}
	for (const deleted of event.deleted) {
		console.log('Cookie deleted:', deleted);
	}
});

// --- Demo sequence ---
(async () => {
	await setCookie();
	await getCookie();
	await listCookies();
	await deleteCookie();
	await listCookies();
})();

				
			

Why it’s better

Practical tips and caveats

Getting started snippet

Example feature detection

				
					if (!('cookieStore' in self)) {
    console.warn('Cookie Store API not supported; falling back to document.cookie.');
    // Provide polyfill or minimal fallback here.
}
				
			

Bottom line

The Cookie Store API brings cookies into the modern web platform: async, typed, and event-driven. Use it to simplify auth state, user preferences, and multi-tab coordination—just remember to feature-detect and keep security attributes tight.

more posts:
Online video streaming platform and digital content management concept with media player interface, cloud library, and multimedia files on laptop, representing content distribution, video marketing
Code

Breaking into the Pipeline: Real-Time Frame Manipulation with the Insertable Streams for MediaStreamTrack API

The experimental Insertable Streams for MediaStreamTrack API closes a long-standing gap in web multimedia by treating live camera feeds as standard Web Streams. By piping individual VideoFrame objects through a TransformStream and recording the transformed output via MediaRecorder, developers can execute frame-by-frame processing—like real-time filtering, watermarking, and computer vision overlays—without relying on hidden canvas hacks.

Discover More »
Apps & Custom Software

What Building Our Own App Taught Us About Building Yours

When Hess WebTech built and launched Tericipe—an Android app that turns printed recipes into a searchable digital collection—in under three months, we had to live with every decision we usually advise clients on. From testing against real-world messy data and handling AI uncertainty to server-side payment security and post-launch maintenance, here are five crucial lessons from our own build that apply to almost any software project.

Discover More »