diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index d373013d4af..10cc7cba931 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -1317,23 +1317,13 @@ export default class MainBackground { this.inlineMenuFieldQualificationService = new InlineMenuFieldQualificationService(); - this.configService - .getFeatureFlag(FeatureFlag.PhishingDetection) - .then((enabled) => { - if (enabled) { - PhishingDetectionService.initialize( - this.auditService, - this.logService, - this.storageService, - this.taskSchedulerService, - ); - } else { - this.logService.info("phishing detection feature flag is disabled."); - } - }) - .catch((error) => - this.logService.error("Failed to check phishing detection feature flag", error), - ); + PhishingDetectionService.initialize( + this.configService, + this.auditService, + this.logService, + this.storageService, + this.taskSchedulerService, + ); this.ipcContentScriptManagerService = new IpcContentScriptManagerService(this.configService); this.ipcService = new IpcBackgroundService(this.logService); diff --git a/apps/browser/src/phishing-detection/background/phishing-detection.service.ts b/apps/browser/src/phishing-detection/background/phishing-detection.service.ts index 7a9f2a9f85c..156ee6ef84d 100644 --- a/apps/browser/src/phishing-detection/background/phishing-detection.service.ts +++ b/apps/browser/src/phishing-detection/background/phishing-detection.service.ts @@ -1,9 +1,8 @@ -// FIXME: Update this file to be type safe and remove this and next line -// @ts-strict-ignore - -import { Subscription } from "rxjs"; +import { mergeMap, Subscription } from "rxjs"; import { AuditService } from "@bitwarden/common/abstractions/audit.service"; +import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum"; +import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service"; import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service"; import { ScheduledTaskNames } from "@bitwarden/common/platform/scheduling"; @@ -39,11 +38,36 @@ export class PhishingDetectionService { private static retryCount = 0; static initialize( + configService: ConfigService, auditService: AuditService, logService: LogService, storageService: AbstractStorageService, taskSchedulerService: TaskSchedulerService, - ) { + ): void { + configService + .getFeatureFlag$(FeatureFlag.PhishingDetection) + .pipe( + mergeMap(async (enabled) => { + if (!enabled) { + logService.info("phishing detection feature flag is disabled."); + } + await PhishingDetectionService.enable( + auditService, + logService, + storageService, + taskSchedulerService, + ); + }), + ) + .subscribe(); + } + + static async enable( + auditService: AuditService, + logService: LogService, + storageService: AbstractStorageService, + taskSchedulerService: TaskSchedulerService, + ): Promise { PhishingDetectionService.auditService = auditService; PhishingDetectionService.logService = logService; PhishingDetectionService.storageService = storageService; @@ -64,7 +88,7 @@ export class PhishingDetectionService { ); // Initial load of cached domains - void this.loadCachedDomains(); + await this.loadCachedDomains(); // Set up periodic updates every 24 hours this.setupPeriodicUpdates();