From df4c2d248ee9f484ffb6d5c685652de8533a45e9 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 21 Jan 2026 12:14:56 -0500 Subject: [PATCH] change from debug to info logs so we can see everything on olena's end --- .../services/phishing-data.service.ts | 14 +++++++---- .../services/phishing-detection.service.ts | 23 ++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/apps/browser/src/dirt/phishing-detection/services/phishing-data.service.ts b/apps/browser/src/dirt/phishing-detection/services/phishing-data.service.ts index 85e91b06a6b..83b0bac2fea 100644 --- a/apps/browser/src/dirt/phishing-detection/services/phishing-data.service.ts +++ b/apps/browser/src/dirt/phishing-detection/services/phishing-data.service.ts @@ -64,6 +64,9 @@ export const PHISHING_DOMAINS_BLOB_KEY = new KeyDefinition( /** Coordinates fetching, caching, and patching of known phishing web addresses */ export class PhishingDataService { + // Track instance count to detect if multiple services are created (potential memory leak) + private static _instanceCount = 0; + private _testWebAddresses = this.getTestWebAddresses().concat("phishing.testcategory.com"); // Included for QA to test in prod private _phishingMetaState = this.globalStateProvider.get(PHISHING_DOMAINS_META_KEY); private _phishingBlobState = this.globalStateProvider.get(PHISHING_DOMAINS_BLOB_KEY); @@ -101,7 +104,10 @@ export class PhishingDataService { private platformUtilsService: PlatformUtilsService, private resourceType: PhishingResourceType = PhishingResourceType.Links, ) { - this.logService.debug("[PhishingDataService] Initializing service..."); + PhishingDataService._instanceCount++; + this.logService.info( + `[PhishingDataService] Initializing service instance #${PhishingDataService._instanceCount}`, + ); this.taskSchedulerService.registerTaskHandler(ScheduledTaskNames.phishingDomainUpdate, () => { this._triggerUpdate$.next(); }); @@ -120,7 +126,7 @@ export class PhishingDataService { */ async isPhishingWebAddress(url: URL): Promise { if (!this._webAddressesSet) { - this.logService.debug("[PhishingDataService] Set not loaded; skipping check"); + this.logService.info("[PhishingDataService] Set not loaded; skipping check"); return false; } @@ -235,7 +241,7 @@ export class PhishingDataService { const webAddresses = devFlagValue("testPhishingUrls") as unknown[]; if (webAddresses && webAddresses instanceof Array) { - this.logService.debug( + this.logService.info( "[PhishingDetectionService] Dev flag enabled for testing phishing detection. Adding test phishing web addresses:", webAddresses, ); @@ -339,7 +345,7 @@ export class PhishingDataService { // Try to load compressed newline blob into an in-memory Set for fast lookups private async _loadBlobToMemory(): Promise { - this.logService.debug("[PhishingDataService] Loading data blob into memory..."); + this.logService.info("[PhishingDataService] Loading data blob into memory..."); try { const blobBase64 = await firstValueFrom(this._phishingBlobState.state$); if (!blobBase64) { diff --git a/apps/browser/src/dirt/phishing-detection/services/phishing-detection.service.ts b/apps/browser/src/dirt/phishing-detection/services/phishing-detection.service.ts index d90e872eef8..c95e219ee89 100644 --- a/apps/browser/src/dirt/phishing-detection/services/phishing-detection.service.ts +++ b/apps/browser/src/dirt/phishing-detection/services/phishing-detection.service.ts @@ -43,6 +43,7 @@ export class PhishingDetectionService { private static _tabUpdated$ = new Subject(); private static _ignoredHostnames = new Set(); private static _didInit = false; + private static _logService: LogService | null = null; static initialize( logService: LogService, @@ -51,17 +52,18 @@ export class PhishingDetectionService { messageListener: MessageListener, ) { if (this._didInit) { - logService.debug("[PhishingDetectionService] Initialize already called. Aborting."); + logService.info("[PhishingDetectionService] Initialize already called. Aborting."); return; } - logService.debug("[PhishingDetectionService] Initialize called. Checking prerequisites..."); + logService.info("[PhishingDetectionService] Initialize called. Checking prerequisites..."); + this._logService = logService; BrowserApi.addListener(chrome.tabs.onUpdated, this._handleTabUpdated.bind(this)); const onContinueCommand$ = messageListener.messages$(PHISHING_DETECTION_CONTINUE_COMMAND).pipe( tap((message) => - logService.debug(`[PhishingDetectionService] user selected continue for ${message.url}`), + logService.info(`[PhishingDetectionService] user selected continue for ${message.url}`), ), concatMap(async (message) => { const url = new URL(message.url); @@ -87,7 +89,7 @@ export class PhishingDetectionService { prev.tabId === curr.tabId && prev.ignored === curr.ignored, ), - tap((event) => logService.debug(`[PhishingDetectionService] processing event:`, event)), + tap((event) => logService.info(`[PhishingDetectionService] processing event:`, event)), concatMap(async ({ tabId, url, ignored }) => { if (ignored) { // The next time this host is visited, block again @@ -118,12 +120,12 @@ export class PhishingDetectionService { distinctUntilChanged(), switchMap((activeUserHasAccess) => { if (!activeUserHasAccess) { - logService.debug( + logService.info( "[PhishingDetectionService] User does not have access to phishing detection service.", ); return EMPTY; } else { - logService.debug("[PhishingDetectionService] Enabling phishing detection service"); + logService.info("[PhishingDetectionService] Enabling phishing detection service"); return merge( phishingDataService.update$, onContinueCommand$, @@ -137,6 +139,9 @@ export class PhishingDetectionService { this._didInit = true; return () => { + logService.info( + `[PhishingDetectionService] Cleanup called. Observers: ${this._tabUpdated$.observers.length}, Ignored hostnames: ${this._ignoredHostnames.size}`, + ); initSub.unsubscribe(); this._didInit = false; @@ -155,6 +160,12 @@ export class PhishingDetectionService { changeInfo: chrome.tabs.OnUpdatedInfo, tab: chrome.tabs.Tab, ): boolean { + // Log observer count to detect listener leaks (should always be 1) + if (this._tabUpdated$.observers.length > 1) { + this._logService?.warning( + `[PhishingDetectionService] Multiple observers detected: ${this._tabUpdated$.observers.length}`, + ); + } this._tabUpdated$.next({ tabId, changeInfo, tab }); // Return value for supporting BrowserApi event listener signature