Permanent storage for Chrome Extension - javascript

I'm looking for the best client side storage for my chrome extension. Local storage isn't suitable as it can be erased by the user deleting their cookies (which is a common occurrence).
What storage can I use for permanent storage in a Chrome Extension (excluding WebSQL - deprecated)?

Try the Chrome storage API.
This API has been optimized to meet the specific storage needs of
extensions. It provides the same storage capabilities as the
localStorage API with the following key differences:
User data can be automatically synced with Chrome sync (using storage.sync).
Your extension's content scripts can directly access user data without the need for a background page.
A user's extension settings can be persisted even when using split incognito behavior.
It's asynchronous with bulk read and write operations, and therefore faster than the blocking and serial localStorage API.
User data can be stored as objects (the localStorage API stores data in strings).
Enterprise policies configured by the administrator for the extension can be read (using storage.managed with a schema).

Related

Sharing storage between instances of same web app

I built a web application that i have running on multiple raspberry pis, I wanted to add storage that is shared by all the web app instances. Basically what I want to achieve is for each instance I open in my browser it saves the device name and URL to my browser (Local storage is what I went with but it's not shared) the web app would then open the storage read all previously accessed pis for easy switching.
I tried to do this using local storage but didn't work as apparently it's per instance and not shared. anyone can suggest a proper way to achieve this ?
Local storage is exactly as it sounds - local to the browser (and machine). It's used to store data between multiple sessions with the same app/website on the same machine/browser. If you want to share some information between multiple instances of the app running on different machines or in multiple different browsers you need to store it on the server.
How to store it on the server is then a separate question alltogether (with a wide range of options, e.g. writing to a file or a database). In any case, the implementation will need to be separate from the client app.
Local storage keys are shared on a single device if requests originate on the same domain.
Consider the following example of how keys could be shared:
You have the domain http://example.com
You have two apps hosted at http://example.com/app1/index.html and http://example.com/app2/index.html
You have a local storage key for last visited where the value is a date string
If you go to app1, it sets the key.
If you go to app2, it will be able to retrieve the key set in app1.
Are you having trouble with getting localstorage to be shared across instances in this manner?
If the apps are on different domains, or you're trying to share information between devices, you'll have to use a server to share the data.
Local storage is local to the current domain. There is no storage that can freely be shared between all web pages built into a browser.
If you have multiple web applications / application instances, they need to know about each other to communicate (via cross-frame messaging) and exchange their URLs to have each store them locally and display them. There are a few approaches how to do that:
have the user explicitly add other domains he knows about so that you can contact them
have the servers announce their presence on the local network (or use a configuration file on each server) so that they know about each other before serving the web site
have a central ("storage") website at a known domain that every application website will contact

Chome Extension - QuotaExceededError localStorage

I'm developing a Chrome extension and using old localStorage to store settings and cache instead of new chrome.storage.local and chrome.storage.sync. I have unlimitedStorage permission and then my cache becomes huge. I'm receiving QuotaExceededError.
How to overcome the problem?
localStorage is not, and will not be, unlimited
The fact that the unlimitedStorage permission does not apply to localStorage is stated in the documentation. The referenced bug, issue 58985, was marked as "WontFix" in December of 2010. Thus, there is not, and will not be, a solution for you to store unlimited data in localStorage. You will need to select some other method of storing your data.
Unlimited storage options
storage.local
Your options include chrome.storage which is explicitly intended for extensions to store data. You can store data that is local to the machine, using storage.local (can be unlimited with the unlimitedStorage permission), or data that is synchronized across the user's Google account, with storage.sync (quota is not set to unlimited by unlimitedStorage).
Web SQL Database
There are other options for storing data. For instance, the Web SQL Database, which is specifically granted unlimited storage by the unlimitedStorage permission.
HTML5 local File API (MDN)
The amount of data you can store with the File API becomes unlimited with the unlimitedStorage permission. You can also separately request a specific quota size with a call to webkitStorageInfo.requestQuota(), without using the unlimitedStorage permission. When you do, the user will be asked to approve the storage request. If you do use the unlimitedStorage permission, you do not need to separately request a quota.
What to use
What is best to use will depend on exactly what you are using storage for. You have provided no information as to your actual use, so there is no way for us to gauge what might be a good fit in your case.
Application cache
As to your issue with the application cache growing to a large size with the unlimitedStorage permission: Yes, the documenation explicitly states that declaring the unlimitedStorage permission will result in the application cache becoming unlimited. If this is an issue, you will need to not declare the unlimitedStorage permission.

Google Chrome Extension save data localy

I'm developing Chrome Extension that runs on my_webpage.com and request user to log in to see the web page. So I need to store password somewhere locally, first I used local storage but the problem is that it won't load data on my_webpage.com when data is saved localy in settings. Is there any other option to read/write data locay with Chrome Extension?
chrome.storage API was created specifically for that purpose.
It's available both to extension scripts (e.g. background) and content scripts.
Note though that this storage is not considered secure (not that there are alternatives that are secure, besides using chrome.identity to store OAuth tokens)
for saving the username or password two things can help u
create database and save values in tables.
write data to file in json format and read from file to load data

storing json data locally, should I use cookie or html5 local storage

I've started developing mobile website using jquery mobile. Since I have to carry accross multiple pages some json data I wonder what would be a better approach, storing that json data inside cookie or using html5 local storage. Both approaches would use jquery.
Scenario would be following:
Home controller returns some initial data as json
User selects some from that initial list
User selection should be stored immediatly on local storage
When navigate further on different page those data should be available (retrieving from local storage)
Either approach will work. The decision on which to use comes down to a handful of points:
Do you need access to the JSON data on the server? If so, it's simpler to use cookies (otherwise you'll have to script the page to manually send the JSON when the server needs it). Or if you rarely/never need the JSON data on the server, you'll save some bandwidth by using local storage.
Do you need to store large amounts of data? With cookies you're limited to 4K per cookie. With local storage you have access to 5 MB of space.
Are you concerned about supporting older browser versions, or some esoteric/less popular browsers that don't have HTML5 support? Cookies will work with a broader range of browsers than local storage.
Further discussion here: Local Storage vs Cookies
localStorage would be better option for your need than cookie.
Cookie send the request to HTTP during every page is loaded.

Offline app : use HTML5 Filesystem API to store MySQL database

I need to build a PHP/MySQL app that allows offline access on iPads (for travelling salesmen often in deep country without internet connection). I have to manage a daily (or on demand when the device is online) sync between the local data and my remote server. I have a large database, which cannot fit in the 5M localStorage limitation. IndexedDB or Filesystem API are not available on Safari (according to http://caniuse.com/).
Is there other ways that would be appropriate to get it done?
Can't you use WebSQL? ( see question What is the maximum size of a Web SQL DB in iOS (Safari) on the iPad? How about LocalStorage? ).
If you coded it for LocalStorage you could easily use that LocalStorage API to access WebSQL on iOS devices...
Perhaps a jump to PhoneGap would solve some of your problems?
Do you need to store ALL data from your database?
I have a library for doing Syncrhonization, it's LocalStorage at the moment but the next update will allow me to use nearly any storage mechanism as it only needs one index. Purging data that is no longer required is on the list too... It's located at https://github.com/forbesmyester/SyncIt and you can even see a presentation courtesy of SkillsMatter / LondonAJAX.

Categories

Resources