I have a simple Chrome extension that uses the chrome.storage API to store tasks in a list. Each time the task list is updated, the array is stored to chrome.storage.sync.
I have two laptops set up with the Chrome extension. I'm logged in to the same Google account on both.
Sometimes when I update the task list on the first laptop, the second laptop will reflect the update in a matter of seconds. But other times, the second laptop won't receive the updates for a long time. It's very inconsistent - sometimes if I quit Chrome and restart it on the second machine, the updated list will be there.
I'm not getting any console errors on either laptop, and the tasks are saved correctly on the first machine - they're just not getting transferred to the second laptop.
The chrome.storage.sync API has a few limits and I'm trying to figure out if I'm breaching one of them. The likeliest one is this:
10 MAX_SUSTAINED_WRITE_OPERATIONS_PER_MINUTE
"The maximum number of set, remove, or clear operations that can be performed each minute, sustained over 10 minutes. Updates that would cause this limit to be exceeded fail immediately and set runtime.lastError."
The way I read that, is that as long as there aren't more than 10 operations per minute for 10 consecutive minutes (at least 100 in total), the limit wouldn't be breached. And if I were breaching this limit, I'd see a console error or the tasks wouldn't save locally.
In general - is there a way to debug problems with Chrome sync? Is it expected to be flakey?
sync , the stored data will automatically be synced to any Chrome browser that the user is logged into, provided the user has sync enabled. When Chrome is offline, Chrome stores the data locally. The next time the browser is online, Chrome syncs the data. Even if a user disables syncing, storage.
Check Sync Settings Right under your profile pic, click on Sync. This is where you can manage sync settings for individual items like bookmarks, extensions, search history and so on. You can click on the Sync everything option to manage these settings individually. In my case, Extensions was toggled on.
# View localStorage keys and valuesClick the Application tab to open the Application panel. Expand the Local Storage menu. Click a domain to view its key-value pairs.
There are problems with reliance on chrome.storage.sync
, yes.
Hitting quota limit may blacklist your extension in memory until Chrome is restarted.
In theory, you can catch a quota error with chrome.storage.set
callback, as it will set chrome.runtime.lastError
, and implement some kind of backoff/buffering.
In practice, there is anecdotal evidence that Chrome (not Google backend) blacklists an extension that breaks limits, and this persists through Chrome session (even if the quota should refresh). This is still not fixed as of 2014-10-16. Has reportedly been fixed.
There is no way to wait for / request a sync.
Unfortunately, chrome.storage.sync
in its current form does not provide an event for remote sync being complete or having an error in case there is no change to local state. As such, if you rely on some value when starting, you can't reliably wait for it. And, as indicated by Chrome devs, that will probably stay this way.
There is no state information exposed.
Actually, forget events. The API does not even expose if Chrome Sync is enabled. A lot of problems would be solved if it did, and exposed the last known sync timestamp. It does not currently; here's a feature request.
Despite all this, chrome.storage.sync
is a useful tool. However, when using it, expect it to be unreliable, and always be mindful of the rate limits; possibly implement your own rate limiting.
For debugging chrome.storage.sync
, you can look under its hood with chrome://sync-internals
page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With