X Tutup
Skip to content

Document CookieStore.set() maxAge option#43353

Merged
hamishwillee merged 4 commits intomdn:mainfrom
chrisdavidmills:cookiestore-set-maxage
Mar 9, 2026
Merged

Document CookieStore.set() maxAge option#43353
hamishwillee merged 4 commits intomdn:mainfrom
chrisdavidmills:cookiestore-set-maxage

Conversation

@chrisdavidmills
Copy link
Contributor

Description

Since version 145, Chrome has supported the CookieStore.set() method's maxAge option; see https://chromestatus.com/feature/5190778418757632.

This PR documents the new option.

Motivation

Additional details

Related issues and pull requests

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner March 6, 2026 14:51
@chrisdavidmills chrisdavidmills requested review from hamishwillee and removed request for a team March 6, 2026 14:51
@github-actions github-actions bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Mar 6, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Preview URLs (2 pages)

(comment last updated: 2026-03-09 19:13:21)

### Setting a cookie with options

This example sets a cookie by passing an `options` object with `name`, `value`, `expires`, and `partitioned`.
This example sets a cookie by passing an `options` object with `name`, `value`, `maxAge`, and `partitioned`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is problematic, in particular because maxAge is less supported that expires. Is there a BCD?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been going in circles about this issue a bit. You are right that it is problematic — afaics, it isn't that easy to feature detect whether a specific option from the options object is supported. For now, I've just put it back the way it was, to using expires.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@hamishwillee hamishwillee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. Perhaps also add an update to https://developer.mozilla.org/en-US/docs/Web/API/CookieStore#setting_cookies to note that you can also use maxAge on browsers where it is supported? (and maybe a link to the set() browser compat)?

@chrisdavidmills
Copy link
Contributor Author

Perhaps also add an update to https://developer.mozilla.org/en-US/docs/Web/API/CookieStore#setting_cookies to note that you can also use maxAge on browsers where it is supported? (and maybe a link to the set() browser compat)?

I've added this.

Copy link
Collaborator

@hamishwillee hamishwillee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much @chrisdavidmills - works for me

@hamishwillee hamishwillee merged commit f26af77 into mdn:main Mar 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup