32

I've made a Chrome extension with an options page. The data is saved in localstorage and works just fine.

Chrome doesn't sync the localstorage to the cloud, just the extensions. This means that any user data will not sync to other computers of the same google account.

I can not find an API at http://developer.chrome.com/extensions/docs.html which allows me to sync the user-chosen preferences.

What methods do you suggest?

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
CasperT
  • 3,425
  • 11
  • 41
  • 56
  • What doesn't sync the localStorage? Are you having trouble syncing between your options page and other pages in the extension? Or are you looking for a technology that will sync options between an extension on one computer and options for the same extension on a different computer for the same user? – npdoty Nov 21 '10 at 08:41
  • The latter. Let us say I have Computer A and computer B with the same user. I install the extension on Computer A and set the option page. Everything works fine and it remembers the options even after pc reboot. On computer b, it has installed itself through syncing, but it has not carried over the saved Options! how do I change that? – CasperT Nov 21 '10 at 12:43
  • Are you using the Cookies API (http://code.google.com/chrome/extensions/cookies.html)? – fncomp Nov 22 '10 at 06:06
  • No. Are these synced. Also, the credential consists of a username and password, so I'd rather not store it in plaintext in a cookie. – CasperT Nov 22 '10 at 13:23
  • 1
    The information on this post is **outdated**. See [Is LocalStorage synchronization for Chrome extensions already available?](http://stackoverflow.com/questions/11427340/is-localstorage-synchronization-for-chrome-extensions-already-available) for the up-to-date information. – Rob W Jul 11 '12 at 09:15

5 Answers5

34

In the (hopefully near) future, you'll be You are now able to store stuff in chrome.storage.sync, and it will be synced automagically.

Unless you need something right now, do consider putting all your configurations in an single object, sometime later you'll be able to just sync it!

Edit: now this is available in stable Chrome!

Camilo Martin
  • 37,236
  • 20
  • 111
  • 154
5

Nathan Moos told you truth :) But you don't need to write it by oneself, you can use Ankit Ahuja solution from Sylebot extension. You will need file js/sync.js. Source code is great, and it works great!

3

You should be able to use HTML5 WebDatabases, but you cannot. See comments below.

fncomp
  • 6,040
  • 3
  • 33
  • 42
  • 3
    Why would this sync, but not localStorage? Both things are HTML5. Is there a reference in the API which mentions they support webdatabases in extension sync? – CasperT Nov 22 '10 at 13:24
  • 1
    Honestly, I just saw that someone from the chromium project suggested that it would be a nice way to go: (https://groups.google.com/group/chromium-extensions/tree/browse_frm/month/2009-09/8f8cb3beddc5ad9a?rnum=31&lnk=ol). Because it works on a separate thread. – fncomp Nov 22 '10 at 19:20
  • is this solution really works ? in the related issue http://code.google.com/p/chromium/issues/detail?id=47327 there is no mentions about this – hamczu Mar 13 '11 at 20:26
  • there was related topic on Stack Overflow: http://stackoverflow.com/questions/4877242/will-a-websql-db-sync-with-chromes-app-sync and the answer was "NO"! – hamczu Mar 13 '11 at 21:03
  • 1
    Too bad, I disagree with @Jannes (in ?id=4877242), regarding the concurrency issues, there is, in the end, going to be a master table, allowing syncing, for which a precise time stamp should be fine for differentiating which record goes in last. IMO, to sync the DB or not should definitely be a user decision :( – fncomp Mar 29 '11 at 04:43
2

You could serialize some of the options to a bookmark and tell the user to enable bookmark sync. Then, you could read from the bookmark or build a pseudo-"localStorage" object around the bookmark.

Nathan Moos
  • 3,563
  • 2
  • 22
  • 27
1

You could try to do it with Google Docs like Chrome does with bookmarks. I don't know how far the api reaches but this seems a rather basic operation.

Jan
  • 8,011
  • 3
  • 38
  • 60