From 1a7a3298e24e8207ce02cb4ef238840caefc680b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 3 Apr 2019 13:18:47 -0300 Subject: [PATCH] Be prepared to deal with failure to read user settings Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/507 --- src/js/start.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/js/start.js b/src/js/start.js index 13b55182c..4ed5b9d88 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -296,6 +296,13 @@ const onSystemSettingsReady = function(fetched) { const onFirstFetchReady = function(fetched) { log.info(`First fetch ready ${Date.now()-vAPI.T0} ms after launch`); + // https://github.com/uBlockOrigin/uBlock-issues/issues/507 + // Firefox-specific: somehow `fetched` is undefined under certain + // circumstances even though we asked to load with default values. + if ( fetched instanceof Object === false ) { + fetched = createDefaultProps(); + } + // https://github.com/gorhill/uBlock/issues/747 µb.firstInstall = fetched.version === '0.0.0.0'; @@ -331,11 +338,7 @@ const fromFetch = function(to, fetched) { } }; -/******************************************************************************/ - -const onSelectedFilterListsReady = function() { - log.info(`List selection ready ${Date.now()-vAPI.T0} ms after launch`); - +const createDefaultProps = function() { const fetchableProps = { 'commandShortcuts': [], 'compiledMagic': 0, @@ -361,12 +364,10 @@ const onSelectedFilterListsReady = function() { 'selfieMagic': 0, 'version': '0.0.0.0' }; - toFetch(µb.localSettings, fetchableProps); toFetch(µb.userSettings, fetchableProps); toFetch(µb.restoreBackupSettings, fetchableProps); - - vAPI.storage.get(fetchableProps, onFirstFetchReady); + return fetchableProps; }; /******************************************************************************/ @@ -395,9 +396,10 @@ const onAdminSettingsRestored = function() { onHiddenSettingsReady() ), µb.loadSelectedFilterLists(), - ]).then(( ) => - onSelectedFilterListsReady() - ); + ]).then(( ) => { + log.info(`List selection ready ${Date.now()-vAPI.T0} ms after launch`); + vAPI.storage.get(createDefaultProps(), onFirstFetchReady); + }); }; /******************************************************************************/