Closed danjm closed 1 week ago
Comment from @seaona during weekly review: we are already using IndexedDB in some parts of the codebase (Blockaid feature) and existing implementation could be used as a reference.
Wouldn't IndexedDB
storage be cleared if a use clears their browser storage? Also need to be aware if works in Incognito?
Wouldn't IndexedDB storage be cleared if a use clears their browser storage?
Yes, but that's also the case with storage.local
, no?
Also need to be aware if works in Incognito?
IndexedDB is supposed to work in Incognito mode for most browsers, but there seems to be issues for Firefox (based on this article or this article)
Closing this issue, as we'll end up including this work in the vault recovery flow work: https://github.com/MetaMask/metamask-extension/pull/23056
What is this about?
Currently we use https://developer.chrome.com/docs/extensions/reference/api/storage#property-local for persisting state.
We believe that https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API is more reliable and performant.
We should switch.
We likely will need to implement a class to wrap the IndexedDB api, and then we should be able to swap the use of
storage.local
with the use of that class.Scenario
No response
Design
No response
Technical Details
Technical refinement:
There are 2 store in codebase based on build env:
ReadOnlyNetworkStore
for testing andLocalStore
for normal build, which means we.ReadOnlyNetworkStore
: This store retrieves its state from a network source (in this case, a server serving a JSON file at http://localhost:12345/state.json). It does not persist the state in a traditional storage medium like local storage. It's a read-only store meant for loading data from the network.ExtensionStore
: This store uses the browser's local storage API (specifically browser.storage.local) to persist data across browser sessions. It handles reading and writing the state in a persistent manner, and state will be retained even after the extension or browser is closed.Reference In blockaid to save / retrieve / delete filed and validate using checksum https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/lib/ppom/indexed-db-backend.ts
For
ExtensionStore
:_init
to initialize database andcreateObjectStore
._getObjectStore
to conduct actions to opendedindexedDB
set
to indexDB_writeToDB
way, which usesTransactionMode.READ_WRITE
to access_getObjectStore
get
to indexDB_readFromDB
way, which usesTransactionMode.READ_ONLY
to access_getObjectStore
setMetadata
For
ReadOnlyNetworkStore
:For e2e tests: Write e2e test to validate the state, which covers
Documentation Could use this script to index the data from console
Threat Modeling Framework
No response
Acceptance Criteria
We need to maintain the same behavior of localStorage API
chrome.storage.local.get(console.log)
can find storagechrome.storage.local.clear(function() { console.log('All items have been removed from chrome.storage.local.'})
; and refresh, state is back;chrome.storage.local.clear
, toggle extension, it brings us back to to onboarding pageStakeholder review needed before the work gets merged
References
No response