Below are two examples with the current API.
It uses navigator.webkitPersistentStorage.requestQuota
instead of the deprecated window.webkitStorageInfo.queryUsageAndQuota
:
Query Quota
navigator.webkitPersistentStorage.queryUsageAndQuota (
function(usedBytes, grantedBytes) {
console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
},
function(e) { console.log('Error', e); }
);
Request Quota
var requestedBytes = 1024*1024*280;
navigator.webkitPersistentStorage.requestQuota (
requestedBytes, function(grantedBytes) {
console.log('we were granted ', grantedBytes, 'bytes');
}, function(e) { console.log('Error', e); }
);
Here we use navigator.webkitPersistentStorage
to query and request persistent storage quota. You can also use navigator.webkitTemporaryStorage
to work with temporary storage quota.
The current Chrome implementation tracks this specific spec version, which describes things a bit more: https://www.w3.org/TR/quota-api/.
They also specifically explain the difference between temporary
and permanent
here: Temporary data is more like your tmp
folder or a weak reference, in that, things might get deleted on the whim of the system, while permanent data should always inform the user before getting deleted.
You might want to start with a wrapper to escape all the browser compatibility hell that comes with working against Web APIs (many parts of the specs explicitly state: "This is a proposal and may change without any notices"). Dexie, for example, is an actively developed wrapper for IndexedDb.
chromestore.js is another wrapper (but has not been touched in years).