Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome Sync check if enabled via API/Extension?

Tags:

Is it possible to programmatically check if Chrome Sync is configured in Google Chrome?

The reason I ask is that I am coding an Extension for Chrome that depends on Chrome Sync, and would like to check/inform the user if it's not configured.

Before posting this question I checked the obvious places (Chrome Extension APIs, StackExchange, and Google), but so far I haven't had any luck.

If anyone has an idea/solution I'd appreciate the help.

Cheers.

like image 592
cewood Avatar asked Jan 16 '12 07:01

cewood


People also ask

How do I know if Chrome sync is complete?

In the About tab, you can find "Last Synced", if it shows "Just Now" you can be sure that the sync process completed just now, and be sure that everything has been synced. There is one more field "Syncing" which shows the status of sync, if its true it means the syns is being done and you should wait.

Does Google Chrome sync extensions?

Google Chrome lets you sync your bookmarks and extensions so you don't have to add or transfer them to your other computers.


1 Answers

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.

like image 129
Ivan Castellanos Avatar answered Sep 25 '22 03:09

Ivan Castellanos