From 54cb5e22329aec4883c61af3a27f5d3c7ae9d74d Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 22 Apr 2023 10:57:10 -0400 Subject: [PATCH] Properly handle promise rejection from webext.storage.local() API Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2604 --- src/js/cachestorage.js | 24 ++++++++++++++++++++---- src/js/start.js | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/js/cachestorage.js b/src/js/cachestorage.js index 88b2c67ee..241864201 100644 --- a/src/js/cachestorage.js +++ b/src/js/cachestorage.js @@ -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) diff --git a/src/js/start.js b/src/js/start.js index eb109432c..166871e2a 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -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;