Skip to content

Conversation

@aamuley
Copy link
Collaborator

@aamuley aamuley commented Nov 11, 2025

… scope

To fix #284 and #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

Will add some WPTs beyond the missing/invalid url tests in https://github.com/web-platform-tests/wpt/blob/master/cookiestore/cookieStore_subscribe_arguments.https.any.js


Preview | Diff

@aamuley aamuley requested review from DCtheTall and annevk November 11, 2025 14:51
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
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
Collaborator 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

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
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
Collaborator 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

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
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
Collaborator 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
Collaborator 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
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 :)

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
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
Collaborator 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

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
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
Collaborator 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
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

then [=iteration/continue=].
1. Let |cookieName| be the result of running [=UTF-8 decode without BOM=] on |cookie|'s [=cookie/name=].
1. If |cookieName| equals |subscription|'s [=cookie change subscription/name=],
1. If |subscription|'s [=cookie change subscription/name=] is null, or if |cookieName| equals |subscription|'s [=cookie change subscription/name=],
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
1. If |subscription|'s [=cookie change subscription/name=] is null, or if |cookieName| equals |subscription|'s [=cookie change subscription/name=],
1. If |subscription|'s [=cookie change subscription/name=] is null or |cookieName| is |subscription|'s [=cookie change subscription/name=],

1. [=Normalize=] |name|.
1. Let |url| be |registration|'s [=service worker registration/scope url=].
1. If |entry|["{{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
Member

Choose a reason for hiding this comment

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

Suggested change
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.
1. If |url| is failure or |url| does not start with |registration|'s [=service worker registration/scope url=], then [=reject=] |p| with a {{TypeError}} and abort these steps.

@annevk
Copy link
Member

annevk commented Nov 19, 2025

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

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.

subscribe() and unsubscribe() assume name and url are always given

3 participants