Mind rejected promises from vAPI.storage API

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2604
This commit is contained in:
Raymond Hill 2023-04-22 19:29:54 -04:00
parent 7b3feca9fc
commit 98d4d24f9b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 45 additions and 9 deletions

View File

@ -90,7 +90,38 @@ vAPI.app = {
/******************************************************************************/ /******************************************************************************/
/******************************************************************************/ /******************************************************************************/
vAPI.storage = webext.storage.local; vAPI.storage = {
get(...args) {
return webext.storage.local.get(...args).catch(reason => {
console.log(reason);
});
},
set(...args) {
return webext.storage.local.set(...args).catch(reason => {
console.log(reason);
});
},
remove(...args) {
return webext.storage.local.remove(...args).catch(reason => {
console.log(reason);
});
},
clear(...args) {
return webext.storage.local.clear(...args).catch(reason => {
console.log(reason);
});
},
QUOTA_BYTES: browser.storage.local.QUOTA_BYTES,
};
// Not all platforms support getBytesInUse
if ( webext.storage.local.getBytesInUse instanceof Function ) {
vAPI.storage.getBytesInUse = function(...args) {
return webext.storage.local.getBytesInUse(...args).catch(reason => {
console.log(reason);
});
};
}
/******************************************************************************/ /******************************************************************************/
/******************************************************************************/ /******************************************************************************/

View File

@ -63,30 +63,26 @@ const storageLocal = webext.storage.local;
const cacheStorage = { const cacheStorage = {
name: 'browser.storage.local', name: 'browser.storage.local',
get: (...args) => { get(...args) {
return storageLocal.get(...args).catch(reason => { return storageLocal.get(...args).catch(reason => {
console.log(reason); console.log(reason);
}); });
}, },
set: (...args) => { set(...args) {
return storageLocal.set(...args).catch(reason => { return storageLocal.set(...args).catch(reason => {
console.log(reason); console.log(reason);
}); });
}, },
remove: (...args) => { remove(...args) {
return storageLocal.remove(...args).catch(reason => { return storageLocal.remove(...args).catch(reason => {
console.log(reason); console.log(reason);
}); });
}, },
clear: (...args) => { clear(...args) {
return storageLocal.clear(...args).catch(reason => { return storageLocal.clear(...args).catch(reason => {
console.log(reason); console.log(reason);
}); });
}, },
// Not all platforms support getBytesInUse
getBytesInUse: storageLocal.getBytesInUse
? storageLocal.getBytesInUse.bind(storageLocal)
: undefined,
select: function(selectedBackend) { select: function(selectedBackend) {
let actualBackend = selectedBackend; let actualBackend = selectedBackend;
if ( actualBackend === undefined || actualBackend === 'unset' ) { if ( actualBackend === undefined || actualBackend === 'unset' ) {
@ -113,6 +109,15 @@ const cacheStorage = {
error: undefined error: undefined
}; };
// Not all platforms support getBytesInUse
if ( storageLocal.getBytesInUse instanceof Function ) {
cacheStorage.getBytesInUse = function(...args) {
return storageLocal.getBytesInUse(...args).catch(reason => {
console.log(reason);
});
};
}
// Reassign API entries to that of indexedDB-based ones // Reassign API entries to that of indexedDB-based ones
const selectIDB = async function() { const selectIDB = async function() {
let db; let db;