Chrome storage sync / local solution - javascript

I'm dealing with a dilemma regarding chrome storage.
My use case it that I have a Chrome extension that will store the user's cleaned tabs on a daily basis. One of the requirements is that a history is kept, so I store tabs in an array per day.
My current implementation is to store to chrome.storage.sync, however this storage is way to small for what I intend to use it. It is in fact, rather tiny.
The second option would be to use chrome.storage.local which has sufficient capacity, but we don't want the user's historical tab data to get lost, so this poses the problem that we actually need sync.
The third option is to use localstorage and implement a custom sync to some free remote service like Firebase.
My question is:
Is my understanding right that chrome.storage.sync is only to be used for some configuration data? And is there a straightforward way to force sync the 'local' chrome storage anyhow (might Firebase be an option)?

Is my understanding right that chrome.storage.sync is only to be used for some configuration data?
Yes, being a limited storage, it is intended for maintaining different forms of state data.
And is there a straightforward way to force sync the 'local' chrome
storage anyhow (might Firebase be an option)?
You can definitely use some external service like Firebase to save the user data and gain synchronization on different devices

Related

Is using local db a good way to reduce data read/writes from Cloud Db?

I am using Cloud Firestore in a React Native app and I am trying to reduce the read/writes operations to a minimum. I just thought of using a local DB so that all data fetched from the cloud are saved in the local storage but I would add a snapshot listener to listen for changes whenever the user starts the app.
Is this a good approach for what I am aiming? If not, why? And if yes, do you have any suggestion related to its implementation?
I feel compelled to point out that the other (currently accepted) answer here is flat out incorrect, or at least misleading for a few reasons.
First, Firestore doesn't use HTTP, and the results of queries are never going to be maintained by your typical browser cache. The claims the answer makes about HTTP caching semantics simply do not apply.
Second, the Firestore SDK uses an internal cache, which is enabled by default on Android and iOS, because its sense of cache is almost always going to benefit the end user. Web applications would do well to enable this cache as well. It requires one line of code. This cache will be queried when the client is offline, an can be queried directly if cached results are desired.
Third, adding an additional layer of cache or persistence is actually very necessary for applications that must be fully usable offline. Firestore was not designed to be use fully offline, so having a local-first option is necessary for some applications. The additional cache can be synchronized with Firebase as a sort of cloud backup.
All told, the question is technically too broad for Stack Overflow, and it requires conversation to understand if it's worthwhile to enable Firstore's cache, or add an additional cache on top of that. But it's not patently false that client caching is a bad idea.
No, it's not a good approach.
Caching data is generally a good idea, however implementing this at the DBMS tier will involve writing a lot of code to implement a caching mechanism you have yet to define. The reason it's a bad idea is because JavaScript running on a client already has access to a data tier with very well defined caching semantics already implemented in the the runtime environment - http

Cordova Persistent and Synchronous Storage

I developed a hybrid app with Cordova. I used localStorage for saving some data on devices. Now I need better and persistent storage method. Also I'm looking for a synchronous library. Do you have any advice?
I just find Persisto (https://github.com/mar10/persisto). Can I use this with Cordova?
I just find Persisto. Can I use this with Cordova?
You can use it with Cordova, but it appears to just be a wrapper around localStorage, so is no better/more persistent that using directly using localStorage.
If your Cordova app is targeting iOS then you should be aware that any locally persisted data stored inside the Webview (localStorage, WebSQL, IndexedDB) is considered cache data and therefore can be wiped at any time if the device runs low on storage space.
Also I'm looking for a synchronous library. Do you have any advice?
TL;DR: I don't think you'll find a sychronous interface to a better storage mechanism because the more durable/reliable mechanisms are all inherently asynchronous.
Ultimately it would be better to bite the bullet and rework your code to work with an asynchronous storage mechanism.
For reliable persistent storage that isn't going to get wiped by iOS at a whim, you could use a native SQLite DB via the cordova-sqlite-storage plugin.
For an simple interface to it, you can use a wrapper such as localForage with the cordovaSQLiteDriver adapter.
Or if your content is more file-based, you can store it using cordova-plugin-file to a durable storage location.
Now I need better and persistent storage method.
You can use indexeddb for bettter persistent storage. but all the apis are asychronous and are very complex to implement.
I'm looking for a synchronous library. Do you have any advice?
You can use jsstore for executing the db code sychronously. It provides sql like apis and all the apis are sychronous. So you dont need to worry about not getting latest data etc.
So if you call update, select api one after another, then first update api will be executed and after that select api.
Again it does not make your code asychrnous, it just executed the code in the same order as you call.
Check it out here - http://jsstore.net/
if you are looking for a library to store only keypair value, then you can use KeyStore. Here you dont need to do any setup.
Check out keystore here - https://github.com/ujjwalguptaofficial/KeyStore

Is possible to use the browser storage as a data repository?

With Javascript, exist some way to do a data repository (like the repository pattern for example), using the local storage of the browser? If exist, which compatibility issues between browsers will be found?
I believe this is what you are looking for:
http://coding.smashingmagazine.com/2010/10/11/local-storage-and-how-to-use-it/
It explains how to use the local storage on newer browsers(HTML 5 enabled) without the need for cookies.
I dont think it is possible to save data on browser storage.
other things you can do is using other ways to control that.
1st Way:
data you need to save for the entire session of the user you can globalize in your web by just declaring it as Global variable.
2nd Way
You can use the jQuery plugin called Cookie, you can find it in here
cookie will basically means saving for a longer term then the session. and it is ,in fact, saving data on the user's computer.
My personal suggestion : if you absolutely need to save data and a lot of it in a way, i would either suggest you to save it on your sever (if you have any) or by cookie.
If this answer wasn't enough satisfying for you, please comment and i will try to be more accurate and helpful.

Is there any way to automatically synchronize html5 localstorage between computers

I have a simple offline html5/javascript single-html-file web application that I store in my dropbox. It's a sort of time tracking tool I wrote, and it saves the application data to local storage. Since its for my own use, I like the convenience of an offline app.
But I have several computers, and I've been trying to come up with any sort of hacky way to synchronize this app's data (which is currently using local storage) between my various machines.
It seems that chrome allows synchronization of data, but only for chrome extensions. I also thought I could perhaps have the web page automatically save/load its data from a file in a dropbox folder, but there doesn't appear to be a way to automatically sync with a specific file without user prompting.
I suppose the "obvious" solution is to put the page on a server and store the data in a database. But suppose I don't want a solution which requires me to maintain apps on a server - is there another way, however hacky, to cobble together synchronization?
I even looked for a while to see if there was a vendor offering a web database service - where I could, say, post/get a blob of json on demand, and then somehow have my offline app sync with this service, but the same-origin policy seems to invalidate that plan (and besides I couldn't find such a service).
Is there a tricky/sneaky solution to this problem using chrome, or google drive, or dropbox, or some other tool I'm not aware of? Or am I stuck setting up my own server?
I have been working on a Project that basically gives you versioned localStorage with support for conflict resolution if the same resource ends up being edited by two different clients. At this point there are no drivers for server or client (they are async in-memory at the moment for testing purposes) but there is a lot of code and abstraction to make writing your own drivers really easy... I was even thinking of doing a dropbox/google docs driver myself, except I want DynamoDB/MongoDB and Lawnchair done first.
The code is not dependent on jQuery or any other libraries and there's a pretty full features (though ugly) demo for it as are well.
Anyway the URL is https://github.com/forbesmyester/SyncIt
Apparently, I have exactly the same issue and invetigated it thoroghly. The best choice would be remoteStorage, if you could manage to make it work. It allows to use 3rd party server for data storage or run your own instance.

Chrome extension, Store data

I've read this question: Chrome Extensions & Javasctipy Database but I want an answer with more details and more clear.
How can I store some of my extension settings?
Is it possible to use a database to do such things with JavaScript?
Is there any good tutorial on it?
I don't want to use Local Storage, because I do not want the behavior of SESSIONS
Thanks.
You could use chrome.storage.sync or chrome.storage.local (docs). Both are local storage (not session storage); sync has the additional advantage that it syncs to the user's Google account if they've connected Chrome to it.
The following page lists the storage mechanisms in HTML5. WebSQL gives you a pretty good database for your javascript to use.
http://www.html5rocks.com/en/features/storage
UPDATE: It has been some time since I posted this. WebSQL has been dropped. Browsers will probably still continue to support it, but all the implementations have been SQLite. IndexedDB is the way to go now. I have used it and it is a little hard to get into, but works well for a client side database.
UPDATE AGAIN: Chrome changing things. See T.J. Crowder's Answer.
I believe this is a simple solution for you if you just want to save some settings. It also has some examples, hope it helps.
https://developer.chrome.com/extensions/storage.html

Categories