Google Chrome Sync check if enabled via API/Extension? Google Chrome Sync check if enabled via API/Extension? google-chrome google-chrome

Google Chrome Sync check if enabled via API/Extension?


Google has a page to see the status of your synced account; the URL of that page is https://www.google.com/settings/chrome/sync. Something you can do to see if an account is synced is opening that status page using cross-domain connections that Google allows for extensions (if it doesn't even return 200-OK status is not synced) and then you use a little JavaScript to extract the "Last Sync" date from that page; after that just save it using the chrome.storage.sync API and then a few seconds later check again the "Last Sync" date, if it changed then you can be 99% sure is synced (or if you want to cover the case of slow synchronizations just use setInterval to wait for it).

You can use the following JavaScript to extract the date:

NodeList.prototype.forEach = Array.prototype.forEach;var date = null;document.querySelectorAll("*").forEach(function(ele){    var matches = ele.innerText.match(/\b\d{4}\s\d{2}:\d{2}:\d{2}\b.*/);    if (matches) date = matches[0];});

The first time you save that value

chrome.storage.sync.set({date: date});

And the second time you should compare both values adding something like this:

chrome.storage.sync.get("date", function (old) {    if (date !== old) {        // Is sync!    } else {        // not sync.    }});

Good luck.


I haven't tested this, it's just an idea. Like you, I haven't been able to find any documentation.

The docs at https://developer.chrome.com/extensions/storage.html state that:

Even if a user disables syncing, storage.sync will still work. In this case, it will behave identically to storage.local.

However, storage.sync and storage.local have different QUOTA_BYTES limits; 102,400 and 5,242,880 respectively. According to the docs;

Updates that would cause this limit to be exceeded fail immediately and set runtime.lastError.

So, what happens if you try to set an object of, say, 200,000 bytes into storage.sync? If sync is enabled it should fail - but if sync is disabled, and thus storage.sync is behaving like storage.local, will it succeed? If that does succeed, then you can simply try to set a very big object into sync, check if it succeeded, then remove it, and determine if sync is enabled based on that.


There is an active feature request I made for this:

https://code.google.com/p/chromium/issues/detail?id=361109

However, until this is implemented, there is no way to tell. Sync may be enabled for the account, but disabled on a particular machine or disabled for extensions/apps only.