Skip to content

make cookie subscription name optional, url default to service worker…#291

Merged
annevk merged 7 commits intowhatwg:mainfrom
aamuley:sub-args
Jan 8, 2026
Merged

make cookie subscription name optional, url default to service worker…#291
annevk merged 7 commits intowhatwg:mainfrom
aamuley:sub-args

Conversation

@aamuley
Copy link
Copy Markdown
Member

@aamuley aamuley commented Nov 11, 2025

… scope

To fix mdn/mdn#284 and mdn/mdn#236 make the name optional and match to every available cookie in the service worker scope if it is not provided as an argument. The url of the subscription should default to be the service worker's scope url if omitted

(See WHATWG Working Mode: Changes for more details.)


Preview | Diff

@aamuley aamuley requested review from DCtheTall and annevk November 11, 2025 14:51
Comment thread index.bs Outdated
each member is a <dfn>cookie change subscription</dfn>. A [=cookie change subscription=] is
<span dfn-for="cookie change subscription">
a [=tuple=] of <dfn>name</dfn> and <dfn>url</dfn>.
a [=tuple=] of an optional <dfn>name</dfn> and a <dfn>url</dfn>.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesn't really exist. I think we need to make name be a string or null or some such.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

tried to add the types to that line

Comment thread index.bs Outdated
1. Let |subscription list| be |registration|'s associated [=cookie change subscription list=].
1. [=list/For each=] |entry| in |subscriptions|, run these steps:
1. Let |name| be |entry|["{{CookieStoreGetOptions/name}}"].
1. Let |name| be the |entry|["{{CookieStoreGetOptions/name}}"] if it [=map/exists=].
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it doesn't exist, what happens in the next step?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

made an if block and only attempt to normalize if name is provided

Comment thread index.bs Outdated
Comment thread index.bs Outdated
1. Let |url| be the result of [=basic URL parser|parsing=] |entry|["{{CookieStoreGetOptions/url}}"] with |settings|'s [=environment settings object/API base URL=].
1. Let |url| be |registration|'s [=service worker registration/scope url=].
1. If ["{{CookieStoreGetOptions/url}}"] [=map/exists=], then let |url| be the result of [=basic URL parser|parsing=] |entry|["{{CookieStoreGetOptions/url}}"] with |settings|'s [=environment settings object/API base URL=].
1. If |url| does not start with |registration|'s [=service worker registration/scope url=],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if it's failure?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

added "if |url| is failure, or ..." to the promise rejection in the next step but I can split if thats too long

@aamuley aamuley requested a review from annevk November 12, 2025 15:33
@aamuley
Copy link
Copy Markdown
Member Author

aamuley commented Nov 12, 2025

FYI added some additional testing for a missing name and empty subscription web-platform-tests/wpt#56004

Copy link
Copy Markdown
Member

@DCtheTall DCtheTall left a comment

Choose a reason for hiding this comment

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

LGTM, though I would wait until Anne also approves since he also left a review :)

Comment thread index.bs Outdated
1. If |url| does not start with |registration|'s [=service worker registration/scope url=],
then [=reject=] |p| with a {{TypeError}} and abort these steps.
1. Let |name| be null.
1. If ["{{CookieStoreGetOptions/name}}"] [=map/exists=]:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You omitted |entry| here and in several cases below (also with different keys).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ok i think fixed

Comment thread index.bs Outdated
1. [=Normalize=] |name|.
1. Let |url| be |registration|'s [=service worker registration/scope url=].
1. If ["{{CookieStoreGetOptions/url}}"] [=map/exists=], then set |url| to the result of [=basic URL parser|parsing=] |entry|["{{CookieStoreGetOptions/url}}"] with |settings|'s [=environment settings object/API base URL=].
1. If |url| is failure, or if |url| does not start with |registration|'s [=service worker registration/scope url=], then [=reject=] |p| with a {{TypeError}} and abort these steps.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need for the comma before "or" since we only have two conditions.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

gotcha, removed it

@aamuley aamuley requested a review from annevk November 18, 2025 19:30
Copy link
Copy Markdown
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

We should also consider linking "start with" to https://infra.spec.whatwg.org/#string-starts-with

Comment thread index.bs Outdated
Comment thread index.bs Outdated
@annevk
Copy link
Copy Markdown
Member

annevk commented Nov 19, 2025

Note that before landing you'll need to adjust the commit message a bit to meet the guidelines.

Copy link
Copy Markdown
Member

@DCtheTall DCtheTall left a comment

Choose a reason for hiding this comment

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

Still LGTM, one formatting nit

Comment thread index.bs Outdated
@annevk annevk merged commit dda37ee into whatwg:main Jan 8, 2026
2 checks passed
@annevk
Copy link
Copy Markdown
Member

annevk commented Jan 8, 2026

@aamuley does MDN document this already? If so, we should file an issue against MDN too.

@aamuley
Copy link
Copy Markdown
Member Author

aamuley commented Jan 8, 2026

ok just did that, mdn/content#43382

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[PROJECT] Retitle Web/API pages

3 participants