Profiles & site data

Where the engine keeps cookies and storage, how to give each user their own, and how to see and clear what one site has stored. Available from 0.14.0.

Where the data lives

Cookies, history, local storage, IndexedDB, service workers and autofill live in the app's private app_cefrium directory. Before 0.14.0 they lived in the app's cache directory, which Android may clear when storage runs low; the first start of 0.14.0 moves them once, so users keep their sessions. To choose another directory, call Cefrium.setDataDirectory(dir) before the first browser is created.

Named profiles

A profile keeps its own cookies, storage and cache. Several can be open at once, each in profile-<name> under the data directory.

CefriumProfile work = CefriumProfile.get("work");
CefriumBrowser browser = CefriumBrowser.createWithSurface(activity, work);

// Compose
val state = rememberCefriumViewState(url, profile = CefriumProfile.get("work"))

Names use letters, digits, - and _, up to 64 characters. CefriumProfile.getDefault() is the profile used when none is given, and CefriumProfile.incognito() keeps everything in memory until its last browser closes.

CefriumProfile.delete(name) refuses while a browser of that profile is open. Once the profile has been used in the current run, the engine keeps its databases open, so the data is deleted on the next start, before the engine opens anything; delete returns false in that case. Do not copy or delete a profile's directory yourself while the app runs.

Data per site

profile.listSiteData(sites -> {
    for (CefriumProfile.SiteData d : sites) {
        Log.i(TAG, d.site + ": " + d.storageBytes + " bytes, " + d.cookieCount + " cookies");
    }
});
profile.clearSiteData("https://example.com", () -> Log.i(TAG, "cleared"));

The figures come from the same source as Chrome's per-site storage screen. Storage covers local and session storage, IndexedDB, Cache Storage, File System, service workers and the other per-site stores; cookies are counted separately. Chromium does not attribute the HTTP cache to a site, so it is in neither the size nor the clearing.

Why there is no folder per site: Chromium stores data by type, not by site. One cookie database, one local storage database and one IndexedDB directory hold every site's data, so deleting a file would damage the others. The calls above are the supported way, as in Chrome and WebView.

Sample: cefrium-sample/profiles checks isolation, listing and the deferred deletion on a device.

Downloads (0.16.0)

Downloads belong to a profile, as in Chrome: one keeps going when the browser that started it closes, and the engine keeps the profile's downloads in its history, so they are still there in the next run.

profile.getDownloads(list -> {
    for (CefriumProfile.Download d : list) {
        if (d.getState() == CefriumProfile.DOWNLOAD_INTERRUPTED && d.canResume()) {
            d.resume();   // continues from where it stopped
        }
    }
});
profile.setDownloadObserver(d -> updateNotification(d));