From bfa28b960e00799d8839b6ddf460b4ab1a433913 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 10 Dec 2023 12:33:51 -0500 Subject: [PATCH] Ensure cache storage is selected before access Possibly related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/2136 Also reported internally, steps to reproduce the issue fixed here: - Open uBO's dashboard through 3-dot > Add-ons > uBO > Settings - Bring forth "Filter lists" pane We want the tab to be already opened at next launch - Quit Firefox for Android - Launch Firefox for Android Result: Very long launch time, lists marked as out of date. --- src/js/background.js | 4 ++++ src/js/messaging.js | 4 +++- src/js/start.js | 18 ++++++++---------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 31fc9ddf6..578d8a65c 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -270,6 +270,10 @@ const µBlock = { // jshint ignore:line uiAccentStylesheet: '', }; +µBlock.isReadyPromise = new Promise(resolve => { + µBlock.isReadyResolve = resolve; +}); + µBlock.domainFromHostname = domainFromHostname; µBlock.hostnameFromURI = hostnameFromURI; diff --git a/src/js/messaging.js b/src/js/messaging.js index eef19693f..64098c9eb 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -1565,7 +1565,9 @@ const onMessage = function(request, sender, callback) { }); case 'getLists': - return getLists(callback); + return µb.isReadyPromise.then(( ) => { + getLists(callback); + }); case 'getLocalData': return getLocalData().then(localData => { diff --git a/src/js/start.js b/src/js/start.js index 5b4f0c249..bc38f2b92 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -63,13 +63,6 @@ import { /******************************************************************************/ -// Load all: executed once. - -(async ( ) => { -// >>>>> start of private scope - -/******************************************************************************/ - vAPI.app.onShutdown = ( ) => { staticFilteringReverseLookup.shutdown(); io.updateStop(); @@ -312,10 +305,10 @@ const onHiddenSettingsReady = async ( ) => { } // Maybe override default cache storage - const cacheBackend = await cacheStorage.select( + µb.supportStats.cacheBackend = await cacheStorage.select( µb.hiddenSettings.cacheStorageAPI ); - ubolog(`Backend storage for cache will be ${cacheBackend}`); + ubolog(`Backend storage for cache will be ${µb.supportStats.cacheBackend}`); }; /******************************************************************************/ @@ -379,6 +372,9 @@ const createDefaultProps = ( ) => { /******************************************************************************/ +(async ( ) => { +// >>>>> start of async/await scope + try { ubolog(`Start sequence of loading storage-based data ${Date.now()-vAPI.T0} ms after launch`); @@ -506,5 +502,7 @@ if ( selfieIsValid ) { } ubolog(`All ready ${µb.supportStats.allReadyAfter} after launch`); -// <<<<< end of private scope +µb.isReadyResolve(); + +// <<<<< end of async/await scope })();