Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I sync localStorage across Chrome instances (or use chrome.storage.sync without a published extension)?

Here is my situation: I have written a number of Chrome userscripts for my personal use. Previously, I only had one machine with one instance of Chrome on it, so I was perfectly happy to dump any persistent data into localStorage.

However, I now have multiple machines, and want to use my userscripts on Chrome on all the machines, with my persistent data coming along for the ride. Synchronizing the userscript code itself is straightforward if a bit tedious (stick it in a Bitbucket repo, then pull and manually install), but I have no idea how to synchronize my localStorage data across machines.

I have considered converting my userscripts to proper Chrome extensions and using the chrome.storage API (data stored using chrome.storage.sync apparently can be sync'd if you have a Google account connected to your Chrome instances, which I do). However, here is the issue with that for my use case:

  • In order to synchronize your data, it appears that you have to publish your extension to the Chrome store.
  • I don't want my extensions publically viewable on the Chrome store, since 1.) that costs money; and 2.) some of the extensions are "sensitive" in nature.
  • Even if I were to spend money and thereby solve (1.), the only way I've found to put private extensions on the Chrome store is to be using Google Apps for Work or Education (cf. "Publish a private Chrome app"), and I obviously don't have a personal instance of Google Apps.

So: is there some way for me to either 1.) sync localStorage across machines directly, or 2.) use the chrome.storage.sync API without a publically published Chrome extension?

like image 776
senshin Avatar asked Apr 10 '15 17:04

senshin


People also ask

Does Chrome sync Local Storage?

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.

How do I use Local Storage in Chrome?

It's simple. Just go to the developer tools by pressing F12 , then go to the Application tab. In the Storage section expand Local Storage. After that, you'll see all your browser's local storage there.

Where is Chrome Local Storage stored?

Google Chrome records Web storage data in a SQLite file in the user's profile. The subfolder containing this file is " \AppData\Local\Google\Chrome\User Data\Default\Local Storage " on Windows, and " ~/Library/Application Support/Google/Chrome/Default/Local Storage " on macOS.


Video Answer


1 Answers

This doesn't really answer the question as I originally asked it, but this is what I ended up doing to solve the problem described above, so whatever.

  • In the end, I abandoned the idea of using chrome.storage (the space restrictions on chrome.storage.sync were untenable) and instead wrote my extension using PouchDB, which is a Javascript implementation of CouchDB. PouchDB uses IndexedDB internally, which does have a per-extension limit by default (I think 5 MB? I didn't bother to test), but can be granted unlimited storage by setting the "unlimitedStorage" permission in the extension manifest. PouchDB's storage model is significantly superior to the chrome.storage storage model in basically every way (free revision tracking, a documented sync protocol rather than whatever voodoo chrome.storage.sync does, etc.), and the downsides (an extra dependency, need for a separate remote server [see below], etc.) were not a huge issue for me.
  • I spun up a free EC2 micro instance and installed a CouchDB server on it. CouchDB is a little bit finicky to configure, but works well once that's taken care of. My EC2 instance stopped being free after a year, so I switched to Cloudant, which offers CouchDB-compatible hosting that's free if you use less than $50 worth of storage + bandwidth per month, which I do.
  • I set my extension to point at my Cloudant instance, have it authenticate using plain old HTTP basic authentication (which is fine here, since I'm the only person using this extension, which means I'm free to put my password in plaintext in the extension), and have it sync with the remote instance when requested by the user.
    • The authentication approach I took here (in conjunction with the deployment strategy [see below], etc.) probably has a bunch of holes, but I don't really care; it seems sufficient to stop casual intrusions, which is good enough (I'm not dealing with important or privileged data).
  • Rather than deploying my extension via the Chrome store, which seems complicated and costs money, I now have a rather more ghetto solution whereby I move my extension from my development machine to my other machines by copying the unpacked extension folder into my Dropbox folder and waiting for Dropbox to sync it to my other machines. I then load (or reload) the unpacked extension on my other machines. (This was easier than a Bitbucket-based solution [or any other Git-based solution] because my Windows machines all throw fits when I try to get anything done with Git.)
    • One downside of using Dropbox (or any other solution that involves unpublished unpacked extensions) rather than the Chrome store - Chrome pesters you about disabling non-store extensions every time you open Chrome, even if you're on the Chrome dev channel. In light of Xan's comments below, I'm probably going to take a second look at using the Chrome store as a means of deploying the extension.
like image 88
senshin Avatar answered Sep 21 '22 16:09

senshin