Skip to content

Update CookieStoreManager.subscribe() docs with optional name and url#43390

Open
mohammed-ali-osman wants to merge 3 commits intomdn:mainfrom
mohammed-ali-osman:update-cookie-subscribe
Open

Update CookieStoreManager.subscribe() docs with optional name and url#43390
mohammed-ali-osman wants to merge 3 commits intomdn:mainfrom
mohammed-ali-osman:update-cookie-subscribe

Conversation

@mohammed-ali-osman
Copy link
Copy Markdown
Contributor

Description

  • Updated the subscribe() method docs to reflect the new optional name and url parameters.
  • Clarified that omitting name subscribes to all cookies in the scope, and omitting url defaults to the service worker registration scope.
  • Added examples demonstrating:
    • subscribing to all cookies.
    • subscribing to all cookies with a specific name,
    • handling subscriptions for narrower URL paths,
    • TypeError when URL is outside the service worker scope.
  • Noted that duplicate subscriptions are ignored.

fixes: #43382

@mohammed-ali-osman mohammed-ali-osman requested a review from a team as a code owner March 9, 2026 21:33
@mohammed-ali-osman mohammed-ali-osman requested review from chrisdavidmills and removed request for a team March 9, 2026 21:33
@github-actions github-actions bot added Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed labels Mar 9, 2026
Comment thread files/en-us/web/api/cookiestoremanager/subscribe/index.md Outdated
Comment thread files/en-us/web/api/cookiestoremanager/subscribe/index.md Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 9, 2026

Preview URLs (1 page)

(comment last updated: 2026-04-15 19:05:14)

@chrisdavidmills chrisdavidmills removed their request for review March 10, 2026 07:58
@chrisdavidmills
Copy link
Copy Markdown
Contributor

I'm sorry, but I don't have time to review this over the next few days. I'll see if someone else can look at this.

@mohammed-ali-osman
Copy link
Copy Markdown
Contributor Author

Thank you @chrisdavidmills for letting me know. I appreciate you checking if someone else might be able to review it.

Copy link
Copy Markdown
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

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

Thanks for your PR!

- : An array of objects, each of which has the following properties:
- `name`
- `name` {{optional_inline}}
- : A string with the name of a cookie.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- : A string with the name of a cookie.
- : A string with the name of a cookie. If `name` is omitted, the service worker is subscribed to change events for all cookies that are in scope.

- : A string with the name of a cookie.
- `url`
- `url` {{optional_inline}}
- : A string with the url of a cookie scope. This may be narrower than the scope of the service worker registration.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- : A string with the url of a cookie scope. This may be narrower than the scope of the service worker registration.
- : A string with the url of a cookie scope. This may be narrower than the scope of the service worker registration. If `url` is omitted, it defaults to the scope of the service worker registration.


In this example, the {{domxref("ServiceWorkerRegistration")}} represented by `registration` is subscribing to change events on the cookie named `"cookie1"` with a scope of `"/path1"`.

Duplicate subscriptions (same `name` and `url`) are ignored; only unique subscriptions are added.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think this is terribly clear, and it doesn't really seem in scope for this change. We could say something like:

Duplicate subscriptions are ignored: that is, if a service worker subscribes more than once to the same cookie, it will only receive change notifications once.

However, this doesn't belong in "Examples". Usually we'd put more information in a separate "Description" section, but this doesn't seem like enough to justify that. Maybe it could go under "Return value", as it's somewhat about the result of the call?

await registration.cookies.subscribe(subscriptions);
```

If the `name` property is omitted in a subscription entry, the subscription applies to all cookies within the specified URL scope. Similarly, if the `url` property is omitted, the subscription applies to the entire scope of the service worker registration.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The "Examples" section as a whole is a bit disorganized. It would help to introduce some H3 subheadings for the different examples. You could have:

  • Setting name and url (this could combine the first example and the example that starts "The URL passed to the subscribe() method, may be narrower", since they seem to be talking about the same case really).
  • Setting name only
  • Setting url only
  • Service worker scope restriction

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.

Change arguments to CookieStoreManager's subscribe method

4 participants