Handling and logging of blocked resources (#1481)

This commit is contained in:
nobody 2023-07-11 19:21:33 +02:00
parent 2bb256418b
commit 8e91bbcb9e
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
3 changed files with 24 additions and 7 deletions

View File

@ -97,6 +97,10 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
isListed = helpers.checkAllowlisted(initiatorDomain, interceptor.allowedDomainsGoogleFonts); isListed = helpers.checkAllowlisted(initiatorDomain, interceptor.allowedDomainsGoogleFonts);
// Check if the website is allowed to load Google Fonts // Check if the website is allowed to load Google Fonts
if (interceptor.blockGoogleFonts === true && isListed === false) { 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 { return {
'redirectUrl': chrome.runtime.getURL('resources/google-fonts-placeholder.css') 'redirectUrl': chrome.runtime.getURL('resources/google-fonts-placeholder.css')
}; };
@ -128,13 +132,14 @@ interceptor.handleRequest = function (requestDetails, tabIdentifier, tab) {
*/ */
interceptor._handleMissingCandidate = function (requestUrl, tabIdentifier) { interceptor._handleMissingCandidate = function (requestUrl, tabIdentifier) {
let requestUrlSegments, injectionCount, missingCount; let requestUrlSegments, injectionCount, missingCount, blockedCount;
if (stateManager.showIconBadge === true) { if (stateManager.showIconBadge === true) {
injectionCount = Object.keys(stateManager.tabs[tabIdentifier].injections).length || 0; injectionCount = Object.keys(stateManager.tabs[tabIdentifier].injections).length || 0;
if (stateManager.changeBadgeColorMissingResources === true) { if (stateManager.changeBadgeColorMissingResources === true) {
missingCount = stateManager.tabs[tabIdentifier].missing || 0; 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.setBadgeText(tabIdentifier, injectionCount);
wrappers.setBadgeColoring(tabIdentifier, BadgeSettingMissingResource.TYPE); wrappers.setBadgeColoring(tabIdentifier, BadgeSettingMissingResource.TYPE);
} }

View File

@ -31,7 +31,8 @@ var stateManager = {};
*/ */
stateManager.registerInjection = function (tabIdentifier, injection, url) { 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) { if (injection['result'] !== false) {
injectionIdentifier = injection.source + injection.path; injectionIdentifier = injection.source + injection.path;
@ -42,8 +43,13 @@ stateManager.registerInjection = function (tabIdentifier, injection, url) {
initiatorDomain = helpers.extractDomainFromUrl(url, true) || Address.EXAMPLE; initiatorDomain = helpers.extractDomainFromUrl(url, true) || Address.EXAMPLE;
htmlFilterIsActive = manipulateDOM.checkHtmlFilterEnabled(initiatorDomain); htmlFilterIsActive = manipulateDOM.checkHtmlFilterEnabled(initiatorDomain);
injectionCount = Object.keys(registeredTab.injections).length || 0; if (registeredTab !== undefined) {
missingCount = registeredTab.missing || 0; injectionCount = Object.keys(registeredTab.injections).length || 0;
missingCount = registeredTab.missing || 0;
blockedCount = registeredTab.blocked || 0;
} else {
return;
}
if (injectionCount > 0) { if (injectionCount > 0) {
chrome.browserAction.setTitle({ chrome.browserAction.setTitle({
@ -52,7 +58,7 @@ stateManager.registerInjection = function (tabIdentifier, injection, url) {
}); });
} }
if (stateManager.showIconBadge === true) { if (stateManager.showIconBadge === true) {
if (missingCount > 0 && stateManager.changeBadgeColorMissingResources) { if ((missingCount > 0 || blockedCount > 0) && stateManager.changeBadgeColorMissingResources) {
wrappers.setBadgeColoring(tabIdentifier, BadgeSettingMissingResource.TYPE); wrappers.setBadgeColoring(tabIdentifier, BadgeSettingMissingResource.TYPE);
} else if (htmlFilterIsActive) { } else if (htmlFilterIsActive) {
wrappers.setBadgeColoring(tabIdentifier, BadgeSettingHTMLFilter.TYPE); wrappers.setBadgeColoring(tabIdentifier, BadgeSettingHTMLFilter.TYPE);
@ -156,7 +162,8 @@ stateManager._createTab = function (tab) {
stateManager.tabs[tabIdentifier] = { stateManager.tabs[tabIdentifier] = {
'injections': {}, 'injections': {},
'missing': 0 'missing': 0,
'blocked': 0
}; };
requestFilters = { requestFilters = {
@ -205,6 +212,7 @@ stateManager._updateTab = function (details) {
if (stateManager.tabs[tabIdentifier]) { if (stateManager.tabs[tabIdentifier]) {
stateManager.tabs[tabIdentifier].injections = {}; stateManager.tabs[tabIdentifier].injections = {};
stateManager.tabs[tabIdentifier].missing = 0; stateManager.tabs[tabIdentifier].missing = 0;
stateManager.tabs[tabIdentifier].blocked = 0;
} }
}; };

View File

@ -43,6 +43,10 @@
<li>handlebars.js v4.7.7 (<a href="https://codeberg.org/nobody/LocalCDN/issues/1472">#1472</a>)</li> <li>handlebars.js v4.7.7 (<a href="https://codeberg.org/nobody/LocalCDN/issues/1472">#1472</a>)</li>
<li>Swiper v10.0.3 (<a href="https://codeberg.org/nobody/LocalCDN/issues/1479">#1479</a>)</li> <li>Swiper v10.0.3 (<a href="https://codeberg.org/nobody/LocalCDN/issues/1479">#1479</a>)</li>
</ul> </ul>
<p>Improved</p>
<ul>
<li>Handling and logging of blocked resources (<a href="https://codeberg.org/nobody/LocalCDN/issues/1481">#1481</a>)</li>
</ul>
</div> </div>
<div id="generator-section"> <div id="generator-section">
<div class="topic-label"> <div class="topic-label">