Show active NTP icon correctly on startup

This commit is contained in:
tophf 2017-04-17 18:56:37 +03:00
parent b3b1d4a628
commit dca6aecd20

View File

@ -17,7 +17,6 @@ chrome.webNavigation.onReferenceFragmentUpdated.addListener(data => {
webNavigationListener('styleReplaceAll', data); webNavigationListener('styleReplaceAll', data);
}); });
function webNavigationListener(method, data) { function webNavigationListener(method, data) {
getStyles({matchUrl: data.url, enabled: true, asHash: true}, styles => { getStyles({matchUrl: data.url, enabled: true, asHash: true}, styles => {
// we can't inject chrome:// and chrome-extension:// pages // we can't inject chrome:// and chrome-extension:// pages
@ -263,10 +262,7 @@ function refreshAllTabs() {
function updateIcon(tab, styles) { function updateIcon(tab, styles) {
// while NTP is still loading only process the request for its main frame with a real url if (tab.id < 0) {
// (but when it's loaded we should process style toggle requests from popups, for example)
const isNTP = tab.url == 'chrome://newtab/';
if (isNTP && tab.status != 'complete' || tab.id < 0) {
return; return;
} }
if (styles) { if (styles) {
@ -278,12 +274,9 @@ function updateIcon(tab, styles) {
}); });
return; return;
} }
if (isNTP) { getTabRealURL(tab).then(url =>
getTabRealURL(tab).then(url => getStyles({matchUrl: url, enabled: true, asHash: true},
getStyles({matchUrl: url, enabled: true, asHash: true}, stylesReceived)); stylesReceived));
} else {
getStyles({matchUrl: tab.url, enabled: true, asHash: true}, stylesReceived);
}
function stylesReceived(styles) { function stylesReceived(styles) {
let numStyles = styles.length; let numStyles = styles.length;