From 9b029182de19b66ed9690c4d493076f85f07555b Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Wed, 16 Jun 2021 17:48:16 +0300 Subject: [PATCH 01/11] filter events for tab --- .../filtering-log.__ABSTRACT_API__.js | 1 + .../filtering-log.adguard-api.js | 1 + .../filtering-log/filtering-log.browsers.js | 23 +++++++++++++++++++ .../filter/request-context-storage.js | 12 +++++++--- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Extension/src/background/filter/filtering-log/filtering-log.__ABSTRACT_API__.js b/Extension/src/background/filter/filtering-log/filtering-log.__ABSTRACT_API__.js index e73e6e9fb8..271feda0df 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.__ABSTRACT_API__.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.__ABSTRACT_API__.js @@ -40,6 +40,7 @@ const abstractFilteringLog = { bindStealthActionsToHttpRequestEvent: errorFunction, bindCspReportBlockedToHttpRequestEvent: errorFunction, bindResponseDataToHttpRequestEvent: errorFunction, + cleanUpEventsByTabId: errorFunction, clearEventsByTabId: errorFunction, isOpen: errorFunction, onOpenFilteringLogPage: errorFunction, diff --git a/Extension/src/background/filter/filtering-log/filtering-log.adguard-api.js b/Extension/src/background/filter/filtering-log/filtering-log.adguard-api.js index d9132c666e..9f178cfda6 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.adguard-api.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.adguard-api.js @@ -32,6 +32,7 @@ const apiFilteringLog = { addRemoveHeaderEvent: notImplemented, addScriptInjectionEvent: notImplemented, bindStealthActionsToHttpRequestEvent: notImplemented, + cleanUpEventsByTabId: notImplemented, clearEventsByTabId: notImplemented, isOpen: notImplemented, onOpenFilteringLogPage: notImplemented, diff --git a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js index a15f1c0747..dbf4677f6c 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js @@ -633,6 +633,28 @@ const browsersFilteringLog = (function () { } }; + /** + * Clean up events for tab + * @param tabId + */ + const cleanUpEventsByTabId = function (tabId) { + const tabInfo = tabsInfoMap[tabId]; + + if (tabInfo && tabInfo?.filteringEvents?.length > 0) { + const updatedEvents = tabInfo.filteringEvents + .filter((event) => { + // leave non-document type events + return !(event.requestType === RequestTypes.DOCUMENT) + // or document type with specified statusCode or removeParam parameters + || (event.requestType === RequestTypes.DOCUMENT + && (event.statusCode || event.removeParam)); + }); + const newTabInfo = { ...tabInfo, filteringEvents: updatedEvents }; + tabsInfoMap[tabId] = newTabInfo; + listeners.notifyListeners(listeners.TAB_UPDATE, newTabInfo); + } + }; + /** * Synchronize currently opened tabs with out state */ @@ -719,6 +741,7 @@ const browsersFilteringLog = (function () { bindStealthActionsToHttpRequestEvent, bindCspReportBlockedToHttpRequestEvent, bindResponseDataToHttpRequestEvent, + cleanUpEventsByTabId, clearEventsByTabId, isOpen, diff --git a/Extension/src/background/filter/request-context-storage.js b/Extension/src/background/filter/request-context-storage.js index 5be949ec7b..3c86fb127b 100644 --- a/Extension/src/background/filter/request-context-storage.js +++ b/Extension/src/background/filter/request-context-storage.js @@ -148,9 +148,15 @@ export const requestContextStorage = (function () { }) => { const eventId = getNextEventId(); - // Clears filtering log. If contexts map already contains this requests that means that we caught redirect - if (requestType === RequestTypes.DOCUMENT && !contexts.has(requestId)) { - filteringLog.clearEventsByTabId(tab.tabId); + if (requestType === RequestTypes.DOCUMENT) { + if (contexts.has(requestId)) { + // if contexts map already contains this requests + // that means that we caught redirect or removeParam + filteringLog.cleanUpEventsByTabId(tab.tabId); + } else { + // otherwise delete filtering events + filteringLog.clearEventsByTabId(tab.tabId); + } } const timestamp = Date.now(); From d3e0e7568167c3468298964b14aa0d5e06eaa35a Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Wed, 16 Jun 2021 17:59:38 +0300 Subject: [PATCH 02/11] clean up --- Extension/src/background/webrequest.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Extension/src/background/webrequest.js b/Extension/src/background/webrequest.js index 5b70972d58..35935213dc 100644 --- a/Extension/src/background/webrequest.js +++ b/Extension/src/background/webrequest.js @@ -110,7 +110,7 @@ const webrequestInit = function () { requestUrl, referrerUrl: requestUrl, originUrl, - requestType, + requestType, tab, method, }); @@ -517,7 +517,6 @@ const webrequestInit = function () { const requestContext = requestContextStorage.get(requestId); if (!requestContext) { // Record request for other types - //const { requestId, requestUrl, referrerUrl, originUrl, requestType, tab } = params; requestContextStorage.record({ requestId, requestUrl, From 85375a5a9c175e67e464b94b6991b6456e5e268d Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Thu, 17 Jun 2021 20:25:02 +0300 Subject: [PATCH 03/11] clean up empty events while pushFilteringEvent --- .../filtering-log.__ABSTRACT_API__.js | 2 - .../filtering-log.adguard-api.js | 1 - .../filtering-log/filtering-log.browsers.js | 39 ++++++++----------- .../filter/request-context-storage.js | 12 ++---- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/Extension/src/background/filter/filtering-log/filtering-log.__ABSTRACT_API__.js b/Extension/src/background/filter/filtering-log/filtering-log.__ABSTRACT_API__.js index 271feda0df..433aaa3792 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.__ABSTRACT_API__.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.__ABSTRACT_API__.js @@ -15,7 +15,6 @@ * along with Adguard Browser Extension. If not, see . */ - /** * This is an abstract filtering log module with methods throwing errors if used. * It should be replaced by webpack during compilation @@ -40,7 +39,6 @@ const abstractFilteringLog = { bindStealthActionsToHttpRequestEvent: errorFunction, bindCspReportBlockedToHttpRequestEvent: errorFunction, bindResponseDataToHttpRequestEvent: errorFunction, - cleanUpEventsByTabId: errorFunction, clearEventsByTabId: errorFunction, isOpen: errorFunction, onOpenFilteringLogPage: errorFunction, diff --git a/Extension/src/background/filter/filtering-log/filtering-log.adguard-api.js b/Extension/src/background/filter/filtering-log/filtering-log.adguard-api.js index 9f178cfda6..d9132c666e 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.adguard-api.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.adguard-api.js @@ -32,7 +32,6 @@ const apiFilteringLog = { addRemoveHeaderEvent: notImplemented, addScriptInjectionEvent: notImplemented, bindStealthActionsToHttpRequestEvent: notImplemented, - cleanUpEventsByTabId: notImplemented, clearEventsByTabId: notImplemented, isOpen: notImplemented, onOpenFilteringLogPage: notImplemented, diff --git a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js index dbf4677f6c..2993b7a1b6 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js @@ -241,6 +241,22 @@ const browsersFilteringLog = (function () { filteringEvent.eventId = nanoid(); } + // clean up empty events + if (filteringEvent.requestType === RequestTypes.DOCUMENT + && tabInfo.filteringEvents.length > 0 + && !filteringEvent.requestRule + && !filteringEvent.removeParam) { + const sortedPreviousEvents = tabInfo.filteringEvents + .filter((event) => { + // leave non-document type events + return !(event.requestType === RequestTypes.DOCUMENT) + // or document type with defined statusCode or removeParam parameters + || (event.requestType === RequestTypes.DOCUMENT + && (event.statusCode || event.removeParam)); + }); + tabInfo.filteringEvents = sortedPreviousEvents; + } + tabInfo.filteringEvents.push(filteringEvent); if (tabInfo.filteringEvents.length > REQUESTS_SIZE_PER_TAB) { @@ -633,28 +649,6 @@ const browsersFilteringLog = (function () { } }; - /** - * Clean up events for tab - * @param tabId - */ - const cleanUpEventsByTabId = function (tabId) { - const tabInfo = tabsInfoMap[tabId]; - - if (tabInfo && tabInfo?.filteringEvents?.length > 0) { - const updatedEvents = tabInfo.filteringEvents - .filter((event) => { - // leave non-document type events - return !(event.requestType === RequestTypes.DOCUMENT) - // or document type with specified statusCode or removeParam parameters - || (event.requestType === RequestTypes.DOCUMENT - && (event.statusCode || event.removeParam)); - }); - const newTabInfo = { ...tabInfo, filteringEvents: updatedEvents }; - tabsInfoMap[tabId] = newTabInfo; - listeners.notifyListeners(listeners.TAB_UPDATE, newTabInfo); - } - }; - /** * Synchronize currently opened tabs with out state */ @@ -741,7 +735,6 @@ const browsersFilteringLog = (function () { bindStealthActionsToHttpRequestEvent, bindCspReportBlockedToHttpRequestEvent, bindResponseDataToHttpRequestEvent, - cleanUpEventsByTabId, clearEventsByTabId, isOpen, diff --git a/Extension/src/background/filter/request-context-storage.js b/Extension/src/background/filter/request-context-storage.js index 3c86fb127b..5be949ec7b 100644 --- a/Extension/src/background/filter/request-context-storage.js +++ b/Extension/src/background/filter/request-context-storage.js @@ -148,15 +148,9 @@ export const requestContextStorage = (function () { }) => { const eventId = getNextEventId(); - if (requestType === RequestTypes.DOCUMENT) { - if (contexts.has(requestId)) { - // if contexts map already contains this requests - // that means that we caught redirect or removeParam - filteringLog.cleanUpEventsByTabId(tab.tabId); - } else { - // otherwise delete filtering events - filteringLog.clearEventsByTabId(tab.tabId); - } + // Clears filtering log. If contexts map already contains this requests that means that we caught redirect + if (requestType === RequestTypes.DOCUMENT && !contexts.has(requestId)) { + filteringLog.clearEventsByTabId(tab.tabId); } const timestamp = Date.now(); From 07ef9e3adb66d93b2dde05053d9a418d7db362fd Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Fri, 18 Jun 2021 15:08:44 +0300 Subject: [PATCH 04/11] add clearOnlyEmpty flag for clearEventsByTabId for wiping empty events --- .../filtering-log/filtering-log.browsers.js | 47 ++++++++++--------- .../filter/request-context-storage.js | 15 ++++-- Extension/src/background/message-handler.js | 6 ++- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js index 2993b7a1b6..8bba77c779 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js @@ -241,22 +241,6 @@ const browsersFilteringLog = (function () { filteringEvent.eventId = nanoid(); } - // clean up empty events - if (filteringEvent.requestType === RequestTypes.DOCUMENT - && tabInfo.filteringEvents.length > 0 - && !filteringEvent.requestRule - && !filteringEvent.removeParam) { - const sortedPreviousEvents = tabInfo.filteringEvents - .filter((event) => { - // leave non-document type events - return !(event.requestType === RequestTypes.DOCUMENT) - // or document type with defined statusCode or removeParam parameters - || (event.requestType === RequestTypes.DOCUMENT - && (event.statusCode || event.removeParam)); - }); - tabInfo.filteringEvents = sortedPreviousEvents; - } - tabInfo.filteringEvents.push(filteringEvent); if (tabInfo.filteringEvents.length > REQUESTS_SIZE_PER_TAB) { @@ -633,19 +617,40 @@ const browsersFilteringLog = (function () { } }; + /** + * @typedef clearEventsData + * @property {number} tabId + * @property {boolean} [ignorePreserveLog=false] + * @property {boolean} [clearOnlyEmpty=false] + */ + /** * Remove log requests for tab - * @param tabId - * @param {boolean} ignorePreserveLog + * @param {clearEventsData} clearEventsData */ - const clearEventsByTabId = function (tabId, ignorePreserveLog) { + const clearEventsByTabId = function ({ tabId, ignorePreserveLog = false, clearOnlyEmpty = false }) { const tabInfo = tabsInfoMap[tabId]; const preserveLog = ignorePreserveLog ? false : preserveLogEnabled; if (tabInfo && !preserveLog) { - delete tabInfo.filteringEvents; - listeners.notifyListeners(listeners.TAB_RESET, tabInfo); + if (clearOnlyEmpty && tabInfo.filteringEvents?.length > 0) { + // clean up empty events + const sortedPreviousEvents = tabInfo.filteringEvents + .filter((event) => { + // leave non-document type events + return !(event.requestType === RequestTypes.DOCUMENT) + // or document type with defined removeParam parameters + || (event.requestType === RequestTypes.DOCUMENT + // && (event.statusCode || event.removeParam)); + && event.removeParam); + }); + tabInfo.filteringEvents = sortedPreviousEvents; + listeners.notifyListeners(listeners.TAB_UPDATE, tabInfo); + } else { + delete tabInfo.filteringEvents; + listeners.notifyListeners(listeners.TAB_RESET, tabInfo); + } } }; diff --git a/Extension/src/background/filter/request-context-storage.js b/Extension/src/background/filter/request-context-storage.js index 5be949ec7b..e47fe164fe 100644 --- a/Extension/src/background/filter/request-context-storage.js +++ b/Extension/src/background/filter/request-context-storage.js @@ -148,9 +148,18 @@ export const requestContextStorage = (function () { }) => { const eventId = getNextEventId(); - // Clears filtering log. If contexts map already contains this requests that means that we caught redirect - if (requestType === RequestTypes.DOCUMENT && !contexts.has(requestId)) { - filteringLog.clearEventsByTabId(tab.tabId); + // clears filtering log + if (requestType === RequestTypes.DOCUMENT) { + const { tabId } = tab; + if (contexts.has(requestId)) { + // if contexts map already contains this requests + // that means that we caught redirect or removeParam + const SHOULD_CLEAR_EMPTY_EVENTS = true; + filteringLog.clearEventsByTabId({ tabId, clearOnlyEmpty: SHOULD_CLEAR_EMPTY_EVENTS }); + } else { + // otherwise wipe all filtering events + filteringLog.clearEventsByTabId({ tabId }); + } } const timestamp = Date.now(); diff --git a/Extension/src/background/message-handler.js b/Extension/src/background/message-handler.js index 9fee4d6388..011d80d6f2 100644 --- a/Extension/src/background/message-handler.js +++ b/Extension/src/background/message-handler.js @@ -460,10 +460,12 @@ const createMessageHandler = () => { filteringLog.onCloseFilteringLogPage(); break; case MESSAGE_TYPES.CLEAR_EVENTS_BY_TAB_ID: - filteringLog.clearEventsByTabId(data.tabId, data.ignorePreserveLog); + // filteringLog.clearEventsByTabId(data.tabId, data.ignorePreserveLog); + filteringLog.clearEventsByTabId({ tabId: data.tabId, ignorePreserveLog: data.ignorePreserveLog }); break; case MESSAGE_TYPES.REFRESH_PAGE: - filteringLog.clearEventsByTabId(data.tabId); + // filteringLog.clearEventsByTabId(data.tabId); + filteringLog.clearEventsByTabId({ tabId: data.tabId }); await tabsApi.reload(data.tabId); break; case MESSAGE_TYPES.GET_TAB_FRAME_INFO_BY_ID: { From 735b127c1ec92bcc7190ad5e38bf322c53b63e05 Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Fri, 18 Jun 2021 15:10:05 +0300 Subject: [PATCH 05/11] clean up comments --- Extension/src/background/message-handler.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/Extension/src/background/message-handler.js b/Extension/src/background/message-handler.js index 011d80d6f2..cca4db0139 100644 --- a/Extension/src/background/message-handler.js +++ b/Extension/src/background/message-handler.js @@ -460,11 +460,9 @@ const createMessageHandler = () => { filteringLog.onCloseFilteringLogPage(); break; case MESSAGE_TYPES.CLEAR_EVENTS_BY_TAB_ID: - // filteringLog.clearEventsByTabId(data.tabId, data.ignorePreserveLog); filteringLog.clearEventsByTabId({ tabId: data.tabId, ignorePreserveLog: data.ignorePreserveLog }); break; case MESSAGE_TYPES.REFRESH_PAGE: - // filteringLog.clearEventsByTabId(data.tabId); filteringLog.clearEventsByTabId({ tabId: data.tabId }); await tabsApi.reload(data.tabId); break; From cc789427f0233e58023d5a3763e1606eb3f9c878 Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Fri, 18 Jun 2021 16:59:08 +0300 Subject: [PATCH 06/11] rename sortedPreviousEvents to filteredPreviousEvents --- .../background/filter/filtering-log/filtering-log.browsers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js index 8bba77c779..3af01bbb61 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js @@ -636,7 +636,7 @@ const browsersFilteringLog = (function () { if (tabInfo && !preserveLog) { if (clearOnlyEmpty && tabInfo.filteringEvents?.length > 0) { // clean up empty events - const sortedPreviousEvents = tabInfo.filteringEvents + const filteredPreviousEvents = tabInfo.filteringEvents .filter((event) => { // leave non-document type events return !(event.requestType === RequestTypes.DOCUMENT) @@ -645,7 +645,7 @@ const browsersFilteringLog = (function () { // && (event.statusCode || event.removeParam)); && event.removeParam); }); - tabInfo.filteringEvents = sortedPreviousEvents; + tabInfo.filteringEvents = filteredPreviousEvents; listeners.notifyListeners(listeners.TAB_UPDATE, tabInfo); } else { delete tabInfo.filteringEvents; From 7ce5212a2eed67eb1517c108e427de4a0a6765cc Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Fri, 18 Jun 2021 16:59:36 +0300 Subject: [PATCH 07/11] clean up comment --- .../background/filter/filtering-log/filtering-log.browsers.js | 1 - 1 file changed, 1 deletion(-) diff --git a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js index 3af01bbb61..e6325b0726 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js @@ -642,7 +642,6 @@ const browsersFilteringLog = (function () { return !(event.requestType === RequestTypes.DOCUMENT) // or document type with defined removeParam parameters || (event.requestType === RequestTypes.DOCUMENT - // && (event.statusCode || event.removeParam)); && event.removeParam); }); tabInfo.filteringEvents = filteredPreviousEvents; From 41afb10bb2b446cc2471b1d965ac5a9ba60929b0 Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Fri, 18 Jun 2021 17:00:32 +0300 Subject: [PATCH 08/11] ditch SHOULD_CLEAR_EMPTY_EVENTS --- Extension/src/background/filter/request-context-storage.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Extension/src/background/filter/request-context-storage.js b/Extension/src/background/filter/request-context-storage.js index e47fe164fe..3a4f19af9d 100644 --- a/Extension/src/background/filter/request-context-storage.js +++ b/Extension/src/background/filter/request-context-storage.js @@ -154,8 +154,7 @@ export const requestContextStorage = (function () { if (contexts.has(requestId)) { // if contexts map already contains this requests // that means that we caught redirect or removeParam - const SHOULD_CLEAR_EMPTY_EVENTS = true; - filteringLog.clearEventsByTabId({ tabId, clearOnlyEmpty: SHOULD_CLEAR_EMPTY_EVENTS }); + filteringLog.clearEventsByTabId({ tabId, clearOnlyEmpty: true }); } else { // otherwise wipe all filtering events filteringLog.clearEventsByTabId({ tabId }); From d3a1f0a064c7ba65f4d9722c9abe0846a7a975cc Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Fri, 18 Jun 2021 18:57:46 +0300 Subject: [PATCH 09/11] clean up --- .../filtering-log/filtering-log.browsers.js | 30 ++++--------------- .../src/background/filter/request-blocking.js | 8 ++--- .../filter/request-context-storage.js | 14 ++------- Extension/src/background/message-handler.js | 4 +-- 4 files changed, 14 insertions(+), 42 deletions(-) diff --git a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js index e6325b0726..befb134ed4 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js @@ -617,39 +617,19 @@ const browsersFilteringLog = (function () { } }; - /** - * @typedef clearEventsData - * @property {number} tabId - * @property {boolean} [ignorePreserveLog=false] - * @property {boolean} [clearOnlyEmpty=false] - */ - /** * Remove log requests for tab - * @param {clearEventsData} clearEventsData + * @param {number} tabId + * @param {boolean} ignorePreserveLog */ - const clearEventsByTabId = function ({ tabId, ignorePreserveLog = false, clearOnlyEmpty = false }) { + const clearEventsByTabId = function (tabId, ignorePreserveLog = false) { const tabInfo = tabsInfoMap[tabId]; const preserveLog = ignorePreserveLog ? false : preserveLogEnabled; if (tabInfo && !preserveLog) { - if (clearOnlyEmpty && tabInfo.filteringEvents?.length > 0) { - // clean up empty events - const filteredPreviousEvents = tabInfo.filteringEvents - .filter((event) => { - // leave non-document type events - return !(event.requestType === RequestTypes.DOCUMENT) - // or document type with defined removeParam parameters - || (event.requestType === RequestTypes.DOCUMENT - && event.removeParam); - }); - tabInfo.filteringEvents = filteredPreviousEvents; - listeners.notifyListeners(listeners.TAB_UPDATE, tabInfo); - } else { - delete tabInfo.filteringEvents; - listeners.notifyListeners(listeners.TAB_RESET, tabInfo); - } + delete tabInfo.filteringEvents; + listeners.notifyListeners(listeners.TAB_RESET, tabInfo); } }; diff --git a/Extension/src/background/filter/request-blocking.js b/Extension/src/background/filter/request-blocking.js index f53b2e9330..be443ff041 100644 --- a/Extension/src/background/filter/request-blocking.js +++ b/Extension/src/background/filter/request-blocking.js @@ -155,7 +155,7 @@ export const webRequestService = (function () { referrerUrl, requestType, tab, - requestRule + requestRule, }); return isRequestBlockedByRule(requestRule); @@ -449,9 +449,9 @@ export const webRequestService = (function () { const ruleResult = r.getAdvancedModifier().removeParameters(result); if (ruleResult !== result) { filteringLog.addRemoveParamEvent({ - tab, - frameUrl: requestUrl, - requestType, + tab, + frameUrl: requestUrl, + requestType, rule: r, timestamp: Date.now(), }); diff --git a/Extension/src/background/filter/request-context-storage.js b/Extension/src/background/filter/request-context-storage.js index 3a4f19af9d..5be949ec7b 100644 --- a/Extension/src/background/filter/request-context-storage.js +++ b/Extension/src/background/filter/request-context-storage.js @@ -148,17 +148,9 @@ export const requestContextStorage = (function () { }) => { const eventId = getNextEventId(); - // clears filtering log - if (requestType === RequestTypes.DOCUMENT) { - const { tabId } = tab; - if (contexts.has(requestId)) { - // if contexts map already contains this requests - // that means that we caught redirect or removeParam - filteringLog.clearEventsByTabId({ tabId, clearOnlyEmpty: true }); - } else { - // otherwise wipe all filtering events - filteringLog.clearEventsByTabId({ tabId }); - } + // Clears filtering log. If contexts map already contains this requests that means that we caught redirect + if (requestType === RequestTypes.DOCUMENT && !contexts.has(requestId)) { + filteringLog.clearEventsByTabId(tab.tabId); } const timestamp = Date.now(); diff --git a/Extension/src/background/message-handler.js b/Extension/src/background/message-handler.js index cca4db0139..9fee4d6388 100644 --- a/Extension/src/background/message-handler.js +++ b/Extension/src/background/message-handler.js @@ -460,10 +460,10 @@ const createMessageHandler = () => { filteringLog.onCloseFilteringLogPage(); break; case MESSAGE_TYPES.CLEAR_EVENTS_BY_TAB_ID: - filteringLog.clearEventsByTabId({ tabId: data.tabId, ignorePreserveLog: data.ignorePreserveLog }); + filteringLog.clearEventsByTabId(data.tabId, data.ignorePreserveLog); break; case MESSAGE_TYPES.REFRESH_PAGE: - filteringLog.clearEventsByTabId({ tabId: data.tabId }); + filteringLog.clearEventsByTabId(data.tabId); await tabsApi.reload(data.tabId); break; case MESSAGE_TYPES.GET_TAB_FRAME_INFO_BY_ID: { From 4d1694e570aae81185555d08130ea10bff1878f6 Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Fri, 18 Jun 2021 18:58:58 +0300 Subject: [PATCH 10/11] no extra requestContextStorage.record for DOCUMENT-type requests --- Extension/src/background/webrequest.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Extension/src/background/webrequest.js b/Extension/src/background/webrequest.js index 35935213dc..d9cbefbafb 100644 --- a/Extension/src/background/webrequest.js +++ b/Extension/src/background/webrequest.js @@ -104,17 +104,6 @@ const webrequestInit = function () { // Reset tab button state listeners.notifyListeners(listeners.UPDATE_TAB_BUTTON_STATE, tab, true); - // Record request context for the main frame - requestContextStorage.record({ - requestId, - requestUrl, - referrerUrl: requestUrl, - originUrl, - requestType, - tab, - method, - }); - /** * Just to remember! * In the case of the "about:newtab" pages we don't receive onResponseReceived event for the main_frame From e2d55052702fed977e49ad97567699cc8b61694d Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Fri, 18 Jun 2021 19:01:22 +0300 Subject: [PATCH 11/11] revert no default value and fix jsdoc for clearEventsByTabId param ignorePreserveLog --- .../background/filter/filtering-log/filtering-log.browsers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js index befb134ed4..c50e53fab0 100644 --- a/Extension/src/background/filter/filtering-log/filtering-log.browsers.js +++ b/Extension/src/background/filter/filtering-log/filtering-log.browsers.js @@ -620,9 +620,9 @@ const browsersFilteringLog = (function () { /** * Remove log requests for tab * @param {number} tabId - * @param {boolean} ignorePreserveLog + * @param {boolean} [ignorePreserveLog] */ - const clearEventsByTabId = function (tabId, ignorePreserveLog = false) { + const clearEventsByTabId = function (tabId, ignorePreserveLog) { const tabInfo = tabsInfoMap[tabId]; const preserveLog = ignorePreserveLog ? false : preserveLogEnabled;