v145 · Web APIs · Cookies
Cookie Store API maxAge attribute
Chrome 145 adds the maxAge option to the Cookie Store API's cookieStore.set() method. Previously, developers had to compute an absolute expires timestamp to set a cookie lifetime with the async Cookie Store API. maxAge accepts a relative duration in seconds — matching the semantics of the Max-Age attribute in the classic document.cookie string format.
concepts
-
maxAge Demo
Set cookies with
maxAgevalues (short-lived session, hourly, daily, weekly) and read them back immediately. The Cookie Store API returns aexpirestimestamp — confirm themaxAgemaps correctly. -
expires vs maxAge Comparison
Side-by-side comparison of the old
expires: new Date(Date.now() + duration)pattern versus the newmaxAge: secondsshorthand. Shows why relative duration is more robust than absolute timestamps. -
Session Rotator
Rolling-session simulator with a live countdown meter — set, touch, or let the cookie expire. Subscribes to
cookieStore.changeevents so you can see the lifecycle as it happens. -
Cookie Manager
A live cookie manager panel built entirely on the Cookie Store API. Set cookies with a
maxAgeslider, see all stored cookies with expiry bars, and watchcookieStore.changeevents fire in real time when cookies are created or deleted.
why it shipped
The Cookie Store API (cookieStore.set(), cookieStore.get()) was designed as a Promise-based replacement for the legacy document.cookie string. The classic document.cookie format supports Max-Age=N for relative expiry — far more reliable than Expires=date which depends on client clock accuracy. The Cookie Store API initially omitted maxAge, forcing developers to compute new Date(Date.now() + N * 1000) manually and pass it as expires. Chrome 145 adds the maxAge option so both absolute (expires) and relative (maxAge) lifetimes are available in the modern API.
the API
// Before Chrome 145 — had to compute absolute expiry
await cookieStore.set({
name: 'session',
value: 'abc123',
expires: new Date(Date.now() + 3600 * 1000), // 1 hour from now
});
// Chrome 145+ — relative maxAge in seconds
await cookieStore.set({
name: 'session',
value: 'abc123',
maxAge: 3600, // 1 hour — relative, no clock dependency
});
// Works for short-lived cookies too
await cookieStore.set({ name: 'csrf', value: 'xyz', maxAge: 60 }); // 1 minute
// Session cookie (no expiry — deleted when browser closes)
await cookieStore.set({ name: 'temp', value: '123' }); // no maxAge, no expires
// Delete a cookie by setting maxAge: 0
await cookieStore.set({ name: 'old', value: '', maxAge: 0 });