From 0c41eec115bfe74353c0e3ba58d8732504053ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Cla=C3=9Fen?= Date: Wed, 20 Nov 2024 21:54:31 +0100 Subject: [PATCH] Update webextension-packages (location changes no longer need to be externally provided) --- src/background/reporting/index.js | 101 +++++++----------------------- 1 file changed, 23 insertions(+), 78 deletions(-) diff --git a/src/background/reporting/index.js b/src/background/reporting/index.js index 0fea0d18f..23cc93bc1 100644 --- a/src/background/reporting/index.js +++ b/src/background/reporting/index.js @@ -11,7 +11,6 @@ import { setLogLevel, describeLoggers } from '@whotracksme/reporting/reporting'; -import asyncSetup from '/utils/setup.js'; import debug from '/utils/debug.js'; import * as OptionsObserver from '/utils/options-observer.js'; @@ -36,89 +35,35 @@ import webRequestReporter from './webrequest-reporter.js'; } })(); -const setup = asyncSetup('reporting', [ - OptionsObserver.addListener('terms', async function reporting(terms) { - if (terms) { - if (webRequestReporter) { - webRequestReporter.init().catch((e) => { - console.warn( - 'Failed to initialize request reporting. Leaving the module disabled and continue.', - e, - ); - }); - } - await urlReporter.init().catch((e) => { +OptionsObserver.addListener('terms', function reporting(terms) { + if (terms) { + if (webRequestReporter) { + webRequestReporter.init().catch((e) => { console.warn( - 'Failed to initialize reporting. Leaving the module disabled and continue.', + 'Failed to initialize request reporting. Leaving the module disabled and continue.', e, ); }); - } else { - try { - urlReporter.unload(); - } catch (e) { - console.error(e); - } - try { - webRequestReporter?.unload(); - } catch (e) { - console.error(e); - } } - }), -]); - -async function onLocationChange(details) { - try { - setup.pending && (await setup.pending); - } catch (e) { - console.warn('Reporting is unavailable:', e); - return; - } - - if (!urlReporter.isActive) return; - - const { url, frameId, tabId } = details; - if (frameId !== 0 || url === 'about:blank' || url.startsWith('chrome://')) { - return; - } - - // Be aware that the documentation of webNavigation.onCommitted is incomplete - // (https://developer.chrome.com/docs/extensions/reference/webNavigation/#event-onCommitted): - // - // > Fired when a navigation is committed. The document (and the resources - // > it refers to, such as images and subframes) might still be downloading, - // > but at least part of the document has been received from the server and - // > the browser has decided to switch to the new document. - // - // In practice, the event may also trigger for prefetch requests for which - // no tab exists. For instance, it can be reproduced in Chrome by starting - // a Google search from the address bar. Under certain conditions, the first - // search result triggers an extra onCommitted event (even if the user didn't - // click on the link yet). - const tab = await chrome.tabs.get(tabId).catch(() => null); - if (!tab) { - return; - } - - // Don't leak information in private tabs (neither by storing on disk nor - // by initiating HTTP requests). - if (tab.incognito) { - return; - } - - try { - await urlReporter.analyzeUrl(url); - } catch (e) { - console.warn('Unexpected error in reporting module:', e); + urlReporter.init().catch((e) => { + console.warn( + 'Failed to initialize urlReporting. Leaving the module disabled and continue.', + e, + ); + }); + } else { + try { + urlReporter.unload(); + } catch (e) { + console.error(e); + } + try { + webRequestReporter?.unload(); + } catch (e) { + console.error(e); + } } -} - -chrome.webNavigation.onCommitted.addListener(onLocationChange); - -if (__PLATFORM__ === 'chromium' || __PLATFORM__ === 'firefox') { - chrome.webNavigation.onHistoryStateUpdated.addListener(onLocationChange); -} +}); debug.WTM = { communication,