Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get indexedDb quota storage information

I have tried below code to get indexedDb quota storage information

navigator.webkitTemporaryStorage.queryUsageAndQuota ( 
function(usedBytes, grantedBytes) {  
    console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
}, 
function(e) { console.log('Error', e);  }
); 

It is not working and giving the following error.

Property 'webkitTemporaryStorage' does not exist on type 'Navigator'.

Can anyone provide solution for getting indexedDb quota storage information in typescript?

like image 567
kamalav Avatar asked Jan 04 '23 03:01

kamalav


1 Answers

The problem lays in missing TypeScript typing. You can consider this answer.

To solve the issue, one solution is to declare the variable of type any:

let nav: any = navigator;
nav.webkitTemporaryStorage.queryUsageAndQuota ( 
function(usedBytes, grantedBytes) {  
    console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
}, 
function(e) { console.log('Error', e);  }
); 

Another way is to extend the interface of Navigator

interface Navigator {
    webkitTemporaryStorage: {
        queryUsageAndQuota ;
    }
}
like image 111
edkeveked Avatar answered Jan 05 '23 17:01

edkeveked