Properly handle promise rejection from webext.storage.local() API

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2604
This commit is contained in:
Raymond Hill 2023-04-22 10:57:10 -04:00
parent 8939a68e6d
commit 54cb5e2232
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 21 additions and 5 deletions

View File

@ -63,10 +63,26 @@ const storageLocal = webext.storage.local;
const cacheStorage = {
name: 'browser.storage.local',
get: storageLocal.get.bind(storageLocal),
set: storageLocal.set.bind(storageLocal),
remove: storageLocal.remove.bind(storageLocal),
clear: storageLocal.clear.bind(storageLocal),
get: (...args) => {
return storageLocal.get(...args).catch(reason => {
console.log(reason);
});
},
set: (...args) => {
return storageLocal.set(...args).catch(reason => {
console.log(reason);
});
},
remove: (...args) => {
return storageLocal.remove(...args).catch(reason => {
console.log(reason);
});
},
clear: (...args) => {
return storageLocal.clear(...args).catch(reason => {
console.log(reason);
});
},
// Not all platforms support getBytesInUse
getBytesInUse: storageLocal.getBytesInUse
? storageLocal.getBytesInUse.bind(storageLocal)

View File

@ -265,7 +265,7 @@ const onUserSettingsReady = fetched => {
// https://github.com/uBlockOrigin/uBlock-issues/issues/1365
// Wait for removal of invalid cached data to be completed.
const onCacheSettingsReady = async fetched => {
const onCacheSettingsReady = async (fetched = {}) => {
if ( fetched.compiledMagic !== µb.systemSettings.compiledMagic ) {
µb.compiledFormatChanged = true;
µb.selfieIsInvalid = true;