javascript - Google chrome extension how to check if storage is empty? -


how can check if storage in google chrome extension empty? tried lot of possibility nothing worked me.

this simple.

to number of bytes of storage being used may use chrome.storage api.

if store extension details in object called 'settings', can retrieve number of bytes being used in following manner.

function logbytes(bytes) {     console.log(bytes); }  // gets number of bytes used in sync storage area chrome.storage.sync.getbytesinuse(['settings'], logbytes);  // gets number of bytes used in local storage area chrome.storage.local.getbytesinuse(['settings'], logbytes]); 

the getbytesinuse argument takes array of strings or single string, each string representing keys store data wish count bytes for.

if extension not using space (empty) have 0 bytes in use.

further documentation can found @ chrome storage api

expanding on woxxom's comment, can current objects held in storage performing following:

function logbytes(bytes) {     console.log(bytes); }  function getsyncbytes(settings) {     var keys = object.keys(settings);     chrome.storage.sync.getbytesinuse(keys, logbytes); }  function getlocalbytes(settings) {     var keys = object.keys(settings);     chrome.storage.local.getbytesinuse(keys, logbytes); }  chrome.storage.sync.get(null, getsyncbytes); chrome.storage.local.get(null, getlocalbytes); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -