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: allow customizing browser data location #33554
Conversation
1dc0439
to
585ef03
Compare
I have renamed |
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
it is not recommended to write large files here because some environments | ||
may backup this directory to cloud storage. |
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.
Does Chromium have this problem? I would be surprised if Chrome's caches are uploaded to cloud storage on any platform...
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.
Chrome stores all data under %LOCALAPPDATA%/Google/Chrome
, unlike Electron apps it writes nothing to %APPDATA%
.
Also Chrome writes browsing data (i.e. sessionData
) to a subdirectory (%LOCALAPPDATA%/Google/Chrome/User Data/Default
) instead of the root %LOCALAPPDATA%/Google/Chrome
, which is also different from Electron where we mix browsing data and other types of data under the same directory.
We really made some mistakes when choosing where to store data in Electron.
I'm going to expose a few more paths in app.getPath
and write a guide on how to setup the directories to correct locations after this PR.
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.
Hang on—so Chrome can choose the session data directory per-profile, then! Chromium will put things under userData/Profile 1
, userData/Profile 2
and so on. Shouldn't we offer the same capability?
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.
We do the same thing in Electron, sessions created by session.fromPartition
write data to $sessionData/Partitions/$partitionName
subdirectory instead of the root directory.
The difference is Electron writes data of the default session into the root $sessionData
directory, while Chrome browser writes into the User Data/Default
subdirectory.
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.
Hm, Chrome writes to User Data/$partitionName
, right? Default
is a name of a partition.
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.
Yes, Chrome treats the default profile the same with other profiles and writes data to User Data/$name
.
Electron treats the default session specially and writes its data to $sessionData
, the data of other sessions are written into $sessionData/Partitions/$partitionName
instead.
This was because we did not consider the support of multiple sessions in the early days of Electron.
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.
ahhhh, right, got it. Thanks, that makes sense!
@nornagon This PR is still marked as requesting changes from you, can you take another look? |
state, devtools files. By default this points to `userData`. Chromium may | ||
write very large disk cache here, so if your app does not rely on browser | ||
storage like localStorage or cookies to save user data, it is recommended | ||
to set this directory to other locations to avoid polluting the `userData` |
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.
other locations
I think it would be a good idea to recommend a particular location here!
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 is hard to recommend a particular location here within a short paragraph, I would like to introduce a new path that users can easily use in their app app.setPath('sessionData', app.getPath('betterLocation')
, with a guide on where apps should store their data. But I would like to do it in a new pull request, since it is going to be a bunch of new changes that need new reviews.
Merging as API review has been approved but is still showing as pending for some reason. |
Release Notes Persisted
|
* feat: redirect Electron/Chromium cache location * fix: network services should also use browserData * test: browserData * chore: no need to explicitly create dir * feat: browserData => sessionData * test: check existings of specific items * docs: add background on userData and sessionData Co-authored-by: emmanuel.kimmerlin@thomsonreuters.com <emmanuel.kimmerlin@thomsonreuters.com>
Description of Change
This PR adds a new
sessionData
path toapp.setPath
, which allows changing the location where browser data like cookies and disk cache are stored.This is very useful for apps that do not store user information in browser, as they treat browser data as cache and want to store them in cache locations, see also #1404 and #8124.
Before this PR apps can achieve similar effect by changing the path of
userData
, but we should separatesessionData
fromuserData
, as apps may want to store user information inuserData
while storing browser data in cache location.This PR is modified from #30665.
Checklist
npm test
passesRelease Notes
Notes: Add
browserData
toapp.setPath/getPath
.