Update CookieStoreManager.subscribe() docs with optional name and url#43390
Update CookieStoreManager.subscribe() docs with optional name and url#43390mohammed-ali-osman wants to merge 3 commits intomdn:mainfrom
Conversation
|
Preview URLs (1 page) (comment last updated: 2026-04-15 19:05:14) |
|
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. |
|
Thank you @chrisdavidmills for letting me know. I appreciate you checking if someone else might be able to review it. |
| - : An array of objects, each of which has the following properties: | ||
| - `name` | ||
| - `name` {{optional_inline}} | ||
| - : A string with the name of a cookie. |
There was a problem hiding this comment.
| - : 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. |
There was a problem hiding this comment.
| - : 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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
Description
subscribe()method docs to reflect the new optionalnameandurlparameters.TypeErrorwhen URL is outside the service worker scope.fixes: #43382