From 8e91bbcb9e8cd40e5dbf35614eb23a47380c8fc2 Mon Sep 17 00:00:00 2001 From: nobody Date: Tue, 11 Jul 2023 19:21:33 +0200 Subject: [PATCH] Handling and logging of blocked resources (#1481) --- core/interceptor.js | 9 +++++++-- core/state-manager.js | 18 +++++++++++++----- pages/updates/updates.html | 4 ++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/core/interceptor.js b/core/interceptor.js index 7d5416f8..32bbb224 100644 --- a/core/interceptor.js +++ b/core/interceptor.js @@ -97,6 +97,10 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) { isListed = helpers.checkAllowlisted(initiatorDomain, interceptor.allowedDomainsGoogleFonts); // Check if the website is allowed to load Google Fonts if (interceptor.blockGoogleFonts === true && isListed === false) { + console.log(`${LogString.PREFIX} Google fonts blocked ${requestDetails.url}`); + log.append(tab.url, requestDetails.url, '-', true, iframe); + interceptor._handleMissingCandidate(requestDetails.url, tabIdentifier); + ++stateManager.tabs[tabIdentifier].blocked; return { 'redirectUrl': chrome.runtime.getURL('resources/google-fonts-placeholder.css') }; @@ -128,13 +132,14 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) { */ interceptor._handleMissingCandidate = function (requestUrl, tabIdentifier) { - let requestUrlSegments, injectionCount, missingCount; + let requestUrlSegments, injectionCount, missingCount, blockedCount; if (stateManager.showIconBadge === true) { injectionCount = Object.keys(stateManager.tabs[tabIdentifier].injections).length || 0; if (stateManager.changeBadgeColorMissingResources === true) { missingCount = stateManager.tabs[tabIdentifier].missing || 0; - if (missingCount > 0 && injectionCount === 0) { + blockedCount = stateManager.tabs[tabIdentifier].blocked || 0; + if ((missingCount > 0 || blockedCount > 0) && injectionCount === 0) { wrappers.setBadgeText(tabIdentifier, injectionCount); wrappers.setBadgeColoring(tabIdentifier, BadgeSettingMissingResource.TYPE); } diff --git a/core/state-manager.js b/core/state-manager.js index e52f4f22..be1710a4 100644 --- a/core/state-manager.js +++ b/core/state-manager.js @@ -31,7 +31,8 @@ var stateManager = {}; */ stateManager.registerInjection = function (tabIdentifier, injection, url) { - let injectionIdentifier, registeredTab, injectionCount, missingCount, initiatorDomain, htmlFilterIsActive; + let injectionIdentifier, registeredTab, injectionCount, missingCount, blockedCount, + initiatorDomain, htmlFilterIsActive; if (injection['result'] !== false) { injectionIdentifier = injection.source + injection.path; @@ -42,8 +43,13 @@ stateManager.registerInjection = function (tabIdentifier, injection, url) { initiatorDomain = helpers.extractDomainFromUrl(url, true) || Address.EXAMPLE; htmlFilterIsActive = manipulateDOM.checkHtmlFilterEnabled(initiatorDomain); - injectionCount = Object.keys(registeredTab.injections).length || 0; - missingCount = registeredTab.missing || 0; + if (registeredTab !== undefined) { + injectionCount = Object.keys(registeredTab.injections).length || 0; + missingCount = registeredTab.missing || 0; + blockedCount = registeredTab.blocked || 0; + } else { + return; + } if (injectionCount > 0) { chrome.browserAction.setTitle({ @@ -52,7 +58,7 @@ stateManager.registerInjection = function (tabIdentifier, injection, url) { }); } if (stateManager.showIconBadge === true) { - if (missingCount > 0 && stateManager.changeBadgeColorMissingResources) { + if ((missingCount > 0 || blockedCount > 0) && stateManager.changeBadgeColorMissingResources) { wrappers.setBadgeColoring(tabIdentifier, BadgeSettingMissingResource.TYPE); } else if (htmlFilterIsActive) { wrappers.setBadgeColoring(tabIdentifier, BadgeSettingHTMLFilter.TYPE); @@ -156,7 +162,8 @@ stateManager._createTab = function (tab) { stateManager.tabs[tabIdentifier] = { 'injections': {}, - 'missing': 0 + 'missing': 0, + 'blocked': 0 }; requestFilters = { @@ -205,6 +212,7 @@ stateManager._updateTab = function (details) { if (stateManager.tabs[tabIdentifier]) { stateManager.tabs[tabIdentifier].injections = {}; stateManager.tabs[tabIdentifier].missing = 0; + stateManager.tabs[tabIdentifier].blocked = 0; } }; diff --git a/pages/updates/updates.html b/pages/updates/updates.html index bf79a6e5..59784c96 100644 --- a/pages/updates/updates.html +++ b/pages/updates/updates.html @@ -43,6 +43,10 @@
  • handlebars.js v4.7.7 (#1472)
  • Swiper v10.0.3 (#1479)
  • +

    Improved

    +