Skip to content
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

feat: Options parameter for Session.clearData API #41355

Merged
merged 9 commits into from
Apr 1, 2024

Conversation

clavin
Copy link
Member

@clavin clavin commented Feb 15, 2024

Description of Change

Adds an options parameter to the recent Session.clearData API (#40983) to configure what types of data are cleared and scope the behavior to include or exclude specific origins.

Checklist

Release Notes

Notes: Added options parameter to Session.clearData API.

Proposed API (Docs)

ses.clearData([options])

  • options Object (optional)
    • dataTypes String[] (optional) - The types of data to clear. If undefined, will clear all types of data. See method details for possible values.
    • origins String[] (optional) - Clear data for only these origins. Cannot be used with excludeOrigins.
    • excludeOrigins String[] (optional) - Clear data for all origins except these ones. Cannot be used with origins.
    • avoidClosingConnections boolean (optional) - Skips deleting cookies that would close current network connections.
    • originMatchingMode String (optional) - The behavior for matching data to origins. Valid values are "third-parties-included" and "origin-in-all-contexts".

Returns Promise<void> - resolves when all data has been cleared.

Clears various different types of data.

dataTypes may include the following case-sensitive string values:

ℹ️ PR Note:

There are several other data types that the underlying content::BrowsingDataRemover interface supports. In particular, there are multiple categories that pertain to the privacy sandbox that I didn't include as I don't really understand them enough to know if they should be included in an Electron API like this. 🤷

Also, I'm not sure if some of these categories are relevant to electron, like downloads. I don't think Electron stores download information, but I included it just in the narrow chance we do.

I'm open to discussing and revising the list of supported data type categories!

  • Background Fetch: backgroundFetch
  • Cache: cache
  • Cookies: cookies
  • Downloads: downloads
  • File Systems: fileSystems
  • IndexedDB: indexedDB
  • Local Storage: localStorage
  • Service Workers: serviceWorkers
  • WebSQL: webSQL

This method clears more types of data and is more thourough than the
clearStorageData method.

Note: Cookies are stored at a broader scope than origins. When removing cookies and filtering by origins (or excludeOrigins), the cookies will be removed at the registrable domain level. For example, clearing cookies for the origin https://really.specific.origin.example.com/ will end up clearing all cookies for example.com. Clearing cookies for the origin https://my.website.example.co.uk/ will end up clearing all cookies for example.co.uk.

For more information, refer to Chromium's BrowsingDataRemover interface.

Future Work

This may allow us to deprecate some other data clearing APIs we have:

  • clearCache can be deprecated/reimplemented on top of this API.
  • clearStorageData can be equivalently deprecated/reimplemented on top of this API.
    • One corner case is the quotas option, which there is no equivalent for in this proposed API; however, the "syncable" option is now deprecated and open to be cleaned up/removed in the future, and it is treated as the same as the other option. So, put short, this option no longer has a purpose and can be ignored. (To be clear: the other options of clearStorageData have equivalents in this API.)
    • The only other corner case is that the shadercache option would no longer be specifiable on its own, but would be part of cache. All other current storages options have direct mappings in this API.
    • Some of the equivalents in this API may have additional data cleaned up compared to the clearStorageData method, but I suspect these side effects are generally intended when calling a method to clear data.
  • clearHostResolverCache cannot be deprecated or replaced by this API. The underlying Chromium API is not called as part of this API.
  • 〰️ clearAuthCache cannot be easily replaced by this API, but is called as part of this API. While the underlying Chromium API powering this method is called by this API as part of clearing cookies, this API cannot be narrowed down to just calling only this method since clearing cookies has many other effects beyond clearing the auth cache.
  • 〰️ clearCodeCaches cannot be easily replaced by this API, but is called as part of this API. While the underlying Chromium API powering this method is called by this API as part of clearing cache, this API cannot be narrowed down to just calling only this method since clearing cache has many other effects beyond clearing the code cache.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Feb 15, 2024
@clavin clavin added semver/minor backwards-compatible functionality no-backport labels Feb 15, 2024
@clavin clavin changed the title feat: Options parameter for Session.clearBrowsingData API feat: Options parameter for Session.clearData API Feb 20, 2024
@clavin clavin force-pushed the clavin/session-clear-data-api-enhanced-plus-plus branch from 172271f to 2a7614b Compare February 21, 2024 17:30
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Feb 22, 2024
@ckerr ckerr self-requested a review February 25, 2024 00:14
@clavin clavin force-pushed the clavin/session-clear-data-api-enhanced-plus-plus branch from cfd34fc to ccb1696 Compare February 26, 2024 17:46
@clavin clavin force-pushed the clavin/session-clear-data-api-enhanced-plus-plus branch from ccb1696 to 3ad52b7 Compare February 26, 2024 17:51
@clavin clavin marked this pull request as ready for review February 27, 2024 00:45
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Feb 27, 2024
docs/api/session.md Outdated Show resolved Hide resolved
Copy link
Contributor

@zcbenz zcbenz left a comment

Choose a reason for hiding this comment

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

API LGTM

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Mar 5, 2024
Copy link
Member

@samuelmaddock samuelmaddock left a comment

Choose a reason for hiding this comment

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

API LGTM

Love the docs and options validation 👍

docs/api/session.md Outdated Show resolved Hide resolved
shell/browser/api/electron_api_session.cc Show resolved Hide resolved
@electron electron deleted a comment from sham601 Mar 27, 2024
@codebytere
Copy link
Member

@clavin is there any more work to be done here or can this be merged?

@clavin
Copy link
Member Author

clavin commented Mar 27, 2024

@codebytere No more work, please do merge! 😄

@jkleinsc jkleinsc merged commit 3eb94b7 into main Apr 1, 2024
15 checks passed
@jkleinsc jkleinsc deleted the clavin/session-clear-data-api-enhanced-plus-plus branch April 1, 2024 16:09
Copy link

release-clerk bot commented Apr 1, 2024

Release Notes Persisted

Added options parameter to Session.clearData API.

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

Successfully merging this pull request may close these issues.

7 participants