Skip to content Skip to sidebar Skip to footer

Chrome.storage.local Persistence

all. I've started developing small extensions using Chrome's various API's, and although things are working great, I'm still curious about a few things. Two questions, if you all w

Solution 1:

I'm the author of that API.

chrome.storage.local shouldn't be disappearing except on uninstallation (which sounds like is your case) or, very rarely, on database corruption (and we've seen this particularly happening on System Restore).

chrome.storage.sync works the same way, except that the merge algorithm it uses may cause data loss if 2 machines make conflicting changes. In your case, this might happen if you sign into the machine which is using chrome.storage.sync. More commonly it will be because one machine is offline while making the change, or perhaps the user managed to simultaneously change data on 2 machines (which is why it's recommended to only change data on user action -- we should document that).

For what it's worth -- and we should document this too -- the merge algorithm is last-change-wins and sync-is-source-of-truth -- but any local key/value pairs added won't be deleted. If you have:

{a:1, b:2} on computer A (signed in and syncing), {b:3, c:4} on computer B (not signed in),

and computer B signs in, after doing a full sync the state of storage on both A and B will end up at {a:1, b:2, c:4} because A's data was already part of sync, this the source of truth, but 'c' didn't exist yet so was added.

In this scenario A will have gotten an onChange event adding 'c', and B will have gotten an onChange event adding 'a' and updating 'b' from 3 to 2.

Solution 2:

I spent some time looking at this today for work. My results are at https://github.com/mozilla/application-services/issues/2900#issuecomment-612251230. The behavior of chrome.storage.sync seems to have changed since the accepted answer. In particular, there doesn't appear to be any merging behavior any more. Instead it's all-or-nothing, with whatever object is on the sync server "winning". Deletes are transmitted to the server but not from the server to the other clients.

Post a Comment for "Chrome.storage.local Persistence"