Skip to content

Proposal: add cookies.removeAll() method #690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

aselya
Copy link
Contributor

@aselya aselya commented Sep 18, 2024

Proposal introducing a new API cookies.removeAll()

Copy link
Member

@oliverdunk oliverdunk left a comment

Choose a reason for hiding this comment

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

This generally looks good, thanks! I left a couple of comments.

@aselya aselya changed the title Create Proposal: add cookies.removeAll() method.md Proposal: add cookies.removeAll() method.md Sep 19, 2024
@aselya aselya changed the title Proposal: add cookies.removeAll() method.md Proposal: add cookies.removeAll() method Sep 25, 2024
@aselya
Copy link
Contributor Author

aselya commented Sep 25, 2024

Wanted to add some context to why I'm proposing this.

When working on updating the implementation of the cookies API to include the hasCrossSiteAncestor value in the partitionKey, the unit testing I added as part of the change, revealed that my new implementation introduced a bug that caused multiple cookies to be removed with cookies.remove(). I caught the bug and fixed it before it was ever merged into chromium.

Despite the behavior being a bug, I found the ability to delete multiple cookies with the same call to be quite useful and thought it made sense to add it to the cookies api.

aselya and others added 7 commits October 1, 2024 10:51
Updating parameters to explicitly reference cookies.remove

Co-authored-by: Rob Wu <[email protected]>
Add more related issues
Update the motivation language to reflect the related issues.
Add link to bug in the motivation
Update the objective to be more explicit about the pain point for developers.
Update language to make `{}` and error
aselya added 2 commits October 8, 2024 08:13
Update case: `partitionKey : {}` to match `cookies.getAll`
Update requirements of details object.
Added more detailed description of host permissions impact on API call
Made update to remove the `top-level site` as an optional stand alone parameter.
Copy link
Member

@oliverdunk oliverdunk left a comment

Choose a reason for hiding this comment

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

This looks good to me! Adding @rdcronin to make sure he is happy before we land.

@aselya
Copy link
Contributor Author

aselya commented May 12, 2025

@xeenon @Rob--W any concerns with this API?

Copy link
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

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

Some examples with non-trivial cases would be nice, but

>
>A `string` representing the ID of the cookie store to find the cookie in. If unspecified, the cookie is looked for by default in the current execution context's cookie store.
>
>[`url`](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/cookies/remove#url)
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
>[`url`](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/cookies/remove#url)
>[`url`](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/cookies/remove#url) optional

The sentence two lines below implies that url can be optional.


### Behavior

The API will remove all cookies that match the `details` object parameter with the exception of the cases outlined in the implementation details.
Copy link
Member

Choose a reason for hiding this comment

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

"all cookies that match" is doing some heavy lifting. Would it be meaningful to refer to cookies.getAll as the primitive? Or are there differences?

Copy link
Collaborator

@rdcronin rdcronin left a comment

Choose a reason for hiding this comment

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

Thanks, @aselya ! Generally LG, but a few comments.

>
>A `string` representing the URL associated with the cookie.
>
>A details object must contain a `url` and/or a `topLevelSite`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: topLevelSite is not a (direct) property here, so maybe tweak to:

>A details object must contain at least a `url` a `partitionKey` with a valid `topLevelSite`.


##### Return

> `Promise<Cookie[]>`:
Copy link
Collaborator

Choose a reason for hiding this comment

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

/cc @Rob--W since I know he normally has thoughts on performance-related aspects.

The existing remove() method doesn't return a full cookie, but rather a subset of its properties: name, partitionKey, storeId, and url. I'm curious if we should perhaps lean on that instead, which avoids serializing quite as much data -- in particular, it avoids passing all the values to the extension (which may be quite large in practice).

WDYT?

(If we go that route, we could introduce a common type for it -- CookieSummary, CookieMetadata, or similar?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants