w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
594 stars 54 forks source link

Web storage in extensions: quota, eviction and unlimitedStorage #388

Open hanguokai opened 1 year ago

hanguokai commented 1 year ago

Peter Coles asked a question[^1] in Chrome extension forum. I rearrange it and post it here.

Here I use "Web Storage" to represent all standards web storages, including Local Storage, Cache Storage, IndexedDB, OPFS, etc.

Quota and Eviction

Web Storage has the limitation of quotas and eviction and related API like StorageManager.persist() and StorageManager.estimate().

Should Web Storage in extensions be protected? Ideally, it should be treated as unlimited and not be evicted by default, i.e. navigator.storage.persisted() return true, like PWA installed Web apps.

Browsers Current Status Future Plan
Chrome not persistent persistent?[^2][^3]
Firefox not persistent ?
Safari ? ?

"unlimitedStorage" permission

Another orthogonal issue is "unlimitedStorage" extension permission.

Browsers current meaning Only applied to browser.storage.local? cover web storage in the future?
Chrome remove 10MB limit No, both extension and web -
Firefox more than web storage limit[^4] Yes ?
Safari remove 5MB limit[^5] Yes ?

[^1]: Web storage eviction question by Peter Coles [^2]: Chromium issue 680392. [^3]: Chromium issue 1209236. [^4]: MDN storage.local [^5]: Safari unlimitedStorage

hanguokai commented 11 months ago

Here is a new article from Chrome about this topic: Storage and cookies in extensions. The article states that:

By default, extensions are subject to the normal quota restrictions on storage, which can be checked by calling navigator.storage.estimate(). Storage can also be evicted under heavy memory pressure, although this is rare. To avoid this:

  • Request the "unlimitedStorage" permission, which affects both extension and web storage APIs and exempts extensions from both quota restrictions and eviction.
  • Call navigator.storage.persist() for protection against eviction.

I will update my original table.