Don't count styles on NTP in Chrome 61+, see #122
This commit is contained in:
parent
f57240d3c1
commit
3ddf812635
|
@ -14,17 +14,24 @@ dbExec().catch((...args) => {
|
||||||
// register all listeners
|
// register all listeners
|
||||||
chrome.runtime.onMessage.addListener(onRuntimeMessage);
|
chrome.runtime.onMessage.addListener(onRuntimeMessage);
|
||||||
|
|
||||||
|
{
|
||||||
|
const listener =
|
||||||
|
URLS.chromeProtectsNTP
|
||||||
|
? webNavigationListenerChrome
|
||||||
|
: webNavigationListener;
|
||||||
|
|
||||||
chrome.webNavigation.onBeforeNavigate.addListener(data =>
|
chrome.webNavigation.onBeforeNavigate.addListener(data =>
|
||||||
webNavigationListener(null, data));
|
listener(null, data));
|
||||||
|
|
||||||
chrome.webNavigation.onCommitted.addListener(data =>
|
chrome.webNavigation.onCommitted.addListener(data =>
|
||||||
webNavigationListener('styleApply', data));
|
listener('styleApply', data));
|
||||||
|
|
||||||
chrome.webNavigation.onHistoryStateUpdated.addListener(data =>
|
chrome.webNavigation.onHistoryStateUpdated.addListener(data =>
|
||||||
webNavigationListener('styleReplaceAll', data));
|
listener('styleReplaceAll', data));
|
||||||
|
|
||||||
chrome.webNavigation.onReferenceFragmentUpdated.addListener(data =>
|
chrome.webNavigation.onReferenceFragmentUpdated.addListener(data =>
|
||||||
webNavigationListener('styleReplaceAll', data));
|
listener('styleReplaceAll', data));
|
||||||
|
}
|
||||||
|
|
||||||
chrome.tabs.onAttached.addListener(tabId => {
|
chrome.tabs.onAttached.addListener(tabId => {
|
||||||
// When an edit page gets attached or detached, remember its state
|
// When an edit page gets attached or detached, remember its state
|
||||||
|
@ -236,10 +243,31 @@ function webNavigationListener(method, {url, tabId, frameId}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function webNavigationListenerChrome(method, data) {
|
||||||
|
// Chrome 61.0.3161+ doesn't run content scripts on NTP
|
||||||
|
if (
|
||||||
|
!data.url.startsWith('https://www.google.') ||
|
||||||
|
!data.url.includes('/_/chrome/newtab?')
|
||||||
|
) {
|
||||||
|
webNavigationListener(method, data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
getTab(data.tabId).then(tab => {
|
||||||
|
if (tab.url === 'chrome://newtab/') {
|
||||||
|
data.url = tab.url;
|
||||||
|
}
|
||||||
|
webNavigationListener(method, data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function updateIcon(tab, styles) {
|
function updateIcon(tab, styles) {
|
||||||
if (tab.id < 0) {
|
if (tab.id < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (URLS.chromeProtectsNTP && tab.url === 'chrome://newtab/') {
|
||||||
|
styles = {};
|
||||||
|
}
|
||||||
if (styles) {
|
if (styles) {
|
||||||
stylesReceived(styles);
|
stylesReceived(styles);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user