Prevent dashboard from loading at browser launch until ready

Related discussion:
- https://github.com/uBlockOrigin/uAssets/discussions/16939

Various feedback of people trying to interact with uBO's dashboard
at browser launch, before uBO's main process is fully initialized,
causing confusion, and potential loss of data.
This commit is contained in:
Raymond Hill 2023-03-16 09:17:36 -04:00
parent 0cfc4ee396
commit 5c92d95143
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
4 changed files with 30 additions and 1 deletions

View file

@ -7,6 +7,9 @@ html, body {
position: relative;
width: 100vw;
}
body.notReady {
display: none;
}
#dashboard-nav {
border: 0;
border-bottom: 1px solid var(--border-1);

View file

@ -10,7 +10,8 @@
<link rel="shortcut icon" type="image/png" href="img/icon_64.png">
</head>
<body>
<body class="notReady">
<div id="dashboard-nav">
<span class="logo"><img data-i18n-title="extName" src="img/ublock.svg"></span><!--
--><button class="tabButton" type="button" data-pane="settings.html" data-i18n="settingsPageName" tabindex="0"></button><!--

View file

@ -102,6 +102,27 @@ if ( self.location.hash.slice(1) === 'no-dashboard.html' ) {
}
(async ( ) => {
// Wait for uBO's main process to be ready
await new Promise(resolve => {
const check = ( ) => {
vAPI.messaging.send('dashboard', {
what: 'readyToFilter'
}).then(response => {
if ( response ) { return resolve(true); }
const iframe = qs$('#iframe');
if ( iframe.src !== '' ) {
iframe.src = '';
}
vAPI.setTimeout(check, 250);
}).catch(( ) => {
vAPI.setTimeout(check, 250);
});
};
check();
});
dom.cl.remove(dom.body, 'notReady');
const results = await Promise.all([
// https://github.com/uBlockOrigin/uBlock-issues/issues/106
vAPI.messaging.send('dashboard', { what: 'dashboardConfig' }),

View file

@ -312,6 +312,10 @@ const onMessage = function(request, sender, callback) {
µb.openNewTab(request.details);
break;
case 'readyToFilter':
response = µb.readyToFilter;
break;
// https://github.com/uBlockOrigin/uBlock-issues/issues/1954
// In case of document-blocked page, navigate to blocked URL instead
// of forcing a reload.