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: allow customizing browser data location #33554

Merged
merged 7 commits into from May 9, 2022
Merged

feat: allow customizing browser data location #33554

merged 7 commits into from May 9, 2022

Conversation

zcbenz
Copy link
Member

@zcbenz zcbenz commented Mar 31, 2022

Description of Change

This PR adds a new sessionData path to app.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 separate sessionData from userData, as apps may want to store user information in userData while storing browser data in cache location.

This PR is modified from #30665.

Checklist

Release Notes

Notes: Add browserData to app.setPath/getPath.

@zcbenz zcbenz added semver/minor backwards-compatible functionality api-review/requested 🗳 no-backport labels Mar 31, 2022
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Mar 31, 2022
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Apr 7, 2022
shell/app/electron_main_delegate.cc Outdated Show resolved Hide resolved
shell/browser/browser.cc Outdated Show resolved Hide resolved
docs/api/app.md Outdated Show resolved Hide resolved
@zcbenz zcbenz force-pushed the browser-data branch 5 times, most recently from 1dc0439 to 585ef03 Compare April 14, 2022 10:20
@jkleinsc jkleinsc self-assigned this Apr 18, 2022
@zcbenz
Copy link
Member Author

zcbenz commented Apr 27, 2022

I have renamed browserData to sessionData, and added tests to verify the locations of service worker, localStorage, etc. are the in the right location.

docs/api/app.md Outdated Show resolved Hide resolved
@nornagon
Copy link
Member

API LGTM

Copy link
Contributor

@jkleinsc jkleinsc 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

Comment on lines +641 to +642
it is not recommended to write large files here because some environments
may backup this directory to cloud storage.
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

@zcbenz zcbenz May 4, 2022

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.

Copy link
Member

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!

@zcbenz
Copy link
Member Author

zcbenz commented May 5, 2022

@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`
Copy link
Member

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!

Copy link
Member Author

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.

@jkleinsc
Copy link
Contributor

jkleinsc commented May 9, 2022

Merging as API review has been approved but is still showing as pending for some reason.

@jkleinsc jkleinsc merged commit 9483e71 into main May 9, 2022
@jkleinsc jkleinsc deleted the browser-data branch May 9, 2022 14:26
@release-clerk
Copy link

release-clerk bot commented May 9, 2022

Release Notes Persisted

Add browserData to app.setPath/getPath.

khalwa pushed a commit to solarwindscloud/electron that referenced this pull request Feb 22, 2023
* 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>
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.

None yet

4 participants