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.
Related
I don't have any idea how to implement this. After a bit of search I found out that medium keeps track of the browser and not the user, what is mean is you can access three free articles from each new browser on the same machine (if I am wrong do point it out). I am using React and Firebase for my website.
Edit: I was thinking along the lines of getting some kind of id which is unique to a browser. As cookies and local storage can always be bypassed.
I don't know if it's a clean way to do it but you can associate an IP to an unique counter. Or with a cookie but he can bypass that by cleaning the cookies
The answer would tightly depend on your application setup and especially on the service backing your front store.
If you are using a self-backed backend, for example a nodejs - express based server, within your route middleware you can access the remote address from the req.connection.remoteAddress request property along with the user-agent req.header('User-Agent') and forward these to your datastore being Firebase in this case.
If you are deploying your application to Google Cloud Function, you can then access the remote peer address using the fastly-client-ip request header and still forward this to your storage system.
Use javascript and implement a system that uses a cookie or local-storage to verify how many articles are read on your website.
On most of these websites however you are still able to bypass this limit by clearing the cache or using a incognito window.
To also limit these scenarios you can use a cookie in combination with an IP address, which has its own drawbacks, especially in corporate environments, and mobile connections where IP addresses are heavily shared or changed. Depending on your situation this may matter or not.
Is there any local storage limit in Apache Cordova like in ordinary browser? I want to store large amount of data, and need to know if it has any limit or not... I don't have any sensitive data to store in it.
The documentation says of local storage:
Limited total amount of storage (typically around 5MB).
It also lists other options, like WebSQL, IndexedDB, and plug-ins.
Apache Cordova has a local storage limit of 5 mbs.
There are some other restrictions on the type of data you can store.
As per the below documentation, you can have different storages linked to Apache Cordova as per your requirement. For instance -
LocalStorage :- Have storage limit of 5 mbs
WebSql :- To store structured data (It also has a limitation of 5 mbs)
IndexedDB :- Though the documentation is not very much clear here, but if you are searching for better indexing and having a large database that can provide features of localStorage and WebSql, I would suggest going for IndexedDB. As IndexedDB is a low-level API for client-side storage of significant amounts of structured data, including files/blobs.
Please refer to the Cordova documentation for storage from here:-
Apache Cordova Doc
Below is the link to explore more about IndexedDB:-
Indexed DB
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).
It seems with the current File API, the only way to access a previously added file is to store the entire File Object in local-storage. This can quickly eat away at the browsers memory when multiple files are added.
I was wondering if there is a way to only store some type of reference to the file in local-storage and be able to access that file with its reference.
I tried using the URL.createObjectURL function to generate a URL for the file but that URL is tied to the document and expires when the page is reloaded. Does any alternative exist?
By "quickly eat away at the browser's memory", I'm assuming you mean that your quota for LocalStorage is being used up by the files you're storing there. The local storage quotas are there to prevent websites from using up too much of a user's local disk space. By default, most browsers limit the storage to 5MB per domain.
From the w3 spec, the local storage quota is actually a feature to prevent what you're asking from happening (i.e. a website storing more files on a user's disk than the user has allowed quota for):
User agents should limit the total amount of space allowed for storage areas, because hostile authors could otherwise use this feature to exhaust the user's available disk space.
User agents should guard against sites storing data under their origin's other affiliated sites, e.g. storing up to the limit in a1.example.com, a2.example.com, a3.example.com, etc, circumventing the main example.com storage limit.
User agents may prompt the user when quotas are reached, allowing the user to grant a site more space. This enables sites to store many user-created documents on the user's computer, for instance.
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.