-
Notifications
You must be signed in to change notification settings - Fork 16.1k
feat: Session#clearData
API
#40983
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: Session#clearData
API
#40983
Conversation
The bit about browsing is a good point and I like the idea of using the name |
f796e5a
to
f78936f
Compare
Session#clearBrowsingData
APISession#clearBrowsingData
API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API is designed to be extended in the future with an optional options object parameter. The options will allow users to filter what kinds of data to clear, based on the options available from Chromium's BrowsingDataRemover API. This may also allow us to deprecate some other methods whose functionality become completely subsumed by this expanded method behavior, using the right options.
This is a nice idea @clavin! Thanks for the proposal!
Would it be possible to outline what the full API would look like at endgame? I'm curious about what options would be exposed and what methods would be deprecated.
I discovered Chrome exposes an API like the one proposed here via its extensions APIs. I updated the main post with more information and discussion about it. |
@ckerr While answering this question, I discovered the The future work on this proposed API would look similar to that existing API, but with a change in shape: The method signature would be simply
(As an aside, the |
promise_.Resolve(); | ||
} else { | ||
promise_.RejectWithErrorMessage(base::StringPrintf( | ||
"Failed to clear browsing data (%" PRIu64 ")", failed_data_types)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like v8::Error
can be cast to an object to set additional properties according to the v8 tests.
Maybe the failed data types could be set as a custom property on the error object. It would be a little unusual though as Electron doesn't do this anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had that behavior in a previous revision, and then I realized that it would be better if the failed data types was a set or array of data categories as strings. It would be far more useful to JS code in that form. That mapping doesn't really exist right now but might in a future revision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are two approaches to pick from:
- Keep this error as-is for now, and extend it in the future when the mapping from data types to category strings exists.
- Same as (1) where we add a simple field in the future, but attach an
errorCode
field now with the raw numerical value offailed_data_types
.
There's some rough edges with exposing this raw value to JS though. It's a 64-bit unsigned integer, which could theoretically go beyond the 53-bit limit of normal JS numbers, though there are barely half that number of flags right now. The safe route would be to expose it as a bigint, but that could be confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between this and the clearStorageData
API?
@zcbenz The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API LGTM
Session#clearBrowsingData
APISession#clearData
API
The API name change came after the formal reviews in this PR; however, the change was supported by API WG members I ran it past (and even in a comment up above), and the ultimate goal is to try deprecating the overlapping |
Release Notes Persisted
|
This PR adds a new
clearData
API for clearing out data created by Electron to theSession
class.See the API proposal below for more details, considerations, and future work.
Checklist
npm test
passesRelease Notes
Notes:
clearData
method added toSession
.Proposed API
ses.clearData()
This method corresponds to invoking Chromium's
BrowsingDataRemover
, which can clear many types of data, inlcuding:At present, this method attempt to clear all categories. See the "Future work" section for more information about how this API is designed to be extended.
This method returns a
Promise<void>
that resolves once the data is cleared successfully, or rejects if any categories of data failed to be cleared with an error.Prior Art
While working on this feature, I discovered Chrome exposes this functionality via an extension API:
chrome.browsingData
extension API. (See alternatives below for more discussion on this existing API.)Future Work
This API is designed to be extended in the future with an optional
options
object parameter. The options will allow users to filter what kinds of data to clear, based on the options available from Chromium'sBrowsingDataRemover
API. This may also allow us to deprecate some other methods whose functionality become completely subsumed by this expanded method behavior, using the right options.With this richer configuration, we can also return richer information on the error object in the failure case, like which categories of data failed to be removed.
Alternatives
Multiple, more granular methods
Instead of creating one big supermethod with an options object, we could choose to break it up into individual smaller methods (
clearCacheData
,clearCookiesData
,clearIndexedDBData
, etc.). We may opt to also keep the generalclearData
as a shortcut for calling all of these methods together, effectively clearing all data.The downside is that it's not clear what this granularity would give us. The API surface for
Session
would become even more noisy.Different name
The original proposal mirrored the underlying API name:
clearBrowsingData
. It was decided that it would be more clear to name this method simplyclearData
. You don't really "browse" with Electron apps, which begs the question of what "browsing data" would be for Electron.Not rejecting
Instead of rejecting and potentially throwing errors for what might not be a critical issue, we could make the return value of this method a
Promise<ClearedDataInfo>
that contains information about what categories of data were successfully cleared (not sure that data is useful) and which ones failed.Reuse the extensions API
We could try to go down the route of exposing the existing
chrome.browsingData
extension API instead of implementing our own API on top of the same functionality.However, this approach has some notable disadvantages: