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

Enhance browser.storage.local to allow storing binary data directly #533

Open
scripthunter7 opened this issue Feb 1, 2024 · 6 comments
Open
Labels
enhancement Enhancement or change to an existing feature neutral: chrome Not opposed or supportive from Chrome supportive: firefox Supportive from Firefox supportive: safari Supportive from Safari topic: storage Issues related to persisting data. Topics include browser.storage, web storage, and new APIs.

Comments

@scripthunter7
Copy link

I am reaching out to propose an enhancement to the browser.storage.local functionality. As it stands, this storage currently only supports values that are serializable to JSON.

However, in some scenarios, the ability to store binary data directly can greatly enhance efficiency and performance.

To address this, I recommend integrating support for binary data formats such as Uint8Array, ArrayBuffer, or Blob without the need for JSON serialization. Certainly, maintaining backward compatibility is crucial, since a lot of existing code relies on the current storage.local API.

@gorhill
Copy link

gorhill commented Feb 1, 2024

Another approach to solve this would be to keep browser.storage.local as is while making one or both of the following APIs work reliably in incognito/private mode (related issue #534).

Extensions can already save data while in incognito/private mode through browser.local.storage so I don't see how it helps to prevent them to do so reliably through the above API.

Personally just being able to reliably use the CacheStorage API regardless of incognito/private mode would be welcome.

@hanguokai hanguokai added the topic: storage Issues related to persisting data. Topics include browser.storage, web storage, and new APIs. label Feb 9, 2024
@xeenon xeenon added enhancement Enhancement or change to an existing feature supportive: safari Supportive from Safari and removed needs-triage labels Feb 29, 2024
@Rob--W Rob--W added the supportive: firefox Supportive from Firefox label Mar 4, 2024
@oliverdunk
Copy link
Member

We discussed this during our in-person meeting at TPAC.

In Chrome, the behavior described matches our currently intended behavior for the local and sync storage areas. I believe some (maybe all) of the data types mentioned would work in the storage.session area in Chrome since we use a different implementation. We are neutral on this issue - we don't have any specific objections but are unlikely to prioritize it in the short term since (a) it may require a non-trivial amount of work and (b) we would prefer the usage of web APIs which are more performance optimized.

Safari representatives mentioned that they are keen for developers to use extension storage APIs, and would be interested in this capability as a result.

@tophf
Copy link

tophf commented Oct 5, 2024

Firefox switched to the IndexedDB backend for browser.storage, so it became super fast and capable of storing structured-cloneable data. Can't Chromium use the IndexedDB backend as well?

@oliverdunk
Copy link
Member

Can't Chromium use the IndexedDB backend as well?

It's a reasonable question! I'm not aware of any work being done to investigate the feasibility of that. It sounds like something that should be possible, but is still likely a non-trivial amount of work.

@tophf
Copy link

tophf commented Oct 7, 2024

It should be rather simple to implement in the internal JavaScript shim, i.e. the bindings wouldn't be native, but that shouldn't matter as the performance benefit would be bigger anyway. There might be some caveats like enforcing the 10MB storage quota without unlimitedStorage permission.

@tophf
Copy link

tophf commented Oct 7, 2024

Such implementation (assuming it uses a hardcoded db name like chrome.storage.local, optionally customizable via API and/or manifest.json) would also make the database inspectable in devtools and we could even use the whole IndexedDB API directly if we need to use IDBCursor and other advanced stuff for improved performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement or change to an existing feature neutral: chrome Not opposed or supportive from Chrome supportive: firefox Supportive from Firefox supportive: safari Supportive from Safari topic: storage Issues related to persisting data. Topics include browser.storage, web storage, and new APIs.
Projects
None yet
Development

No branches or pull requests

7 participants