Skip to content

Commit

Permalink
Fix stats leaking & minor fixes (#1333)
Browse files Browse the repository at this point in the history
* Update wtm packages
* Fix Firefox popup click event hack
* Clean up wtm link in the panel
* Add `modified` property to Request constructor
* Use `fromRequestDetails` function for creating request instance
* Fix leaking stats & paused icon
* Fix stats leaking for Safari & Firefox
  • Loading branch information
smalluban authored Oct 16, 2023
1 parent 0c2d602 commit 7fad40f
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 184 deletions.
1 change: 0 additions & 1 deletion extension-manifest-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@ghostery/trackers-preview": "^1.0.0",
"@ghostery/ui": "^1.0.0",
"@sentry/browser": "7.1.1",
"@whotracksme/webextension-packages": "^4.0.1",
"classnames": "^2.3.2",
"d3": "^5.16.0",
"foundation-sites": "^6.6.2",
Expand Down
2 changes: 1 addition & 1 deletion extension-manifest-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@ghostery/trackers-preview": "^1.0.0",
"@ghostery/ui": "^1.0.0",
"@github/relative-time-element": "^4.1.5",
"@whotracksme/webextension-packages": "^4.0.3",
"@whotracksme/webextension-packages": "^4.0.5",
"hybrids": "^8.2.4",
"idb": "^7.1.1",
"jwt-decode": "^3.1.2",
Expand Down
25 changes: 8 additions & 17 deletions extension-manifest-v3/src/background/adblocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Request from './utils/request.js';
import asyncSetup from './utils/setup.js';
import * as engines from './utils/engines.js';

import { setupTabStats, updateTabStats } from './stats.js';
import { updateTabStats } from './stats.js';

let enabledEngines = [];
let pausedDomains = [];
Expand Down Expand Up @@ -333,32 +333,23 @@ function isPaused(details, request) {
if (__PLATFORM__ === 'firefox') {
chrome.webRequest.onBeforeRequest.addListener(
(details) => {
if (details.tabId < 0) return;

const request = Request.fromRequestDetails(details);
const tabId = details.tabId;

// Update stats
if (tabId > -1 && (request.sourceDomain || request.sourceHostname)) {
if (request.isMainFrame() && !request.isHttp && !request.isHttps) {
return;
// INFO: request.source... is only available in Firefox
if (request.sourceDomain || request.sourceHostname) {
if (details.type !== 'main_frame') {
updateTabStats(details.tabId, [request]);
}

Promise.resolve().then(
request.isMainFrame()
? () =>
setupTabStats(
tabId,
request.sourceDomain || request.sourceHostname,
)
: () => updateTabStats(tabId, [request]),
);

if (isPaused(details, request)) return;

for (const name of enabledEngines) {
const engine = engines.get(name);
if (!engine) continue;

if (request.isMainFrame()) {
if (details.type === 'main_frame') {
const htmlFilters = engine.getHtmlFilters(request);
if (htmlFilters.length !== 0) {
filterRequestHTML(
Expand Down
6 changes: 4 additions & 2 deletions extension-manifest-v3/src/background/reporting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ if (__PLATFORM__ === 'firefox') {
if (event === 'observed') {
return;
}
const request = Request.fromRawDetails({

const request = Request.fromRequestDetails({
url: state.url,
sourceUrl: state.tabUrl,
originUrl: state.tabUrl,
});
request.modified = true;

updateTabStats(state.tabId, [request]);
},
});
Expand Down
Loading

0 comments on commit 7fad40f

Please sign in to comment.