Skip to content

Commit

Permalink
Prevent dashboard from loading at browser launch until ready
Browse files Browse the repository at this point in the history
Related discussion:
- uBlockOrigin/uAssets#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.
  • Loading branch information
gorhill committed Mar 16, 2023
1 parent 0cfc4ee commit 5c92d95
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/css/dashboard.css
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/dashboard.html
Expand Up @@ -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><!--
Expand Down
21 changes: 21 additions & 0 deletions src/js/dashboard.js
Expand Up @@ -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' }),
Expand Down
4 changes: 4 additions & 0 deletions src/js/messaging.js
Expand Up @@ -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.
Expand Down

0 comments on commit 5c92d95

Please sign in to comment.