From 7ad7f638d780a385185899f505ddfae2691b3cf4 Mon Sep 17 00:00:00 2001 From: Jimmy Vo Date: Mon, 17 Mar 2025 16:08:28 -0400 Subject: [PATCH] Update code to use Log service. --- apps/browser/src/background/main.background.ts | 4 ++-- .../phishing-detection-browser.service.ts | 2 -- ...gger-phishing-detection-script-injection.ts | 7 +++++-- .../services/phishing-detection.service.ts | 18 ++++++++++++------ 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/apps/browser/src/background/main.background.ts b/apps/browser/src/background/main.background.ts index a3758953134..11653395784 100644 --- a/apps/browser/src/background/main.background.ts +++ b/apps/browser/src/background/main.background.ts @@ -432,8 +432,6 @@ export default class MainBackground { } }; - PhishingDetectionService.setupCheckUrlListener(); - const logoutCallback = async (logoutReason: LogoutReason, userId?: UserId) => await this.logout(logoutReason, userId); @@ -454,6 +452,8 @@ export default class MainBackground { this.keyGenerationService = new KeyGenerationService(this.cryptoFunctionService); this.storageService = new BrowserLocalStorageService(this.logService); + PhishingDetectionService.Initialize(this.logService); + this.intraprocessMessagingSubject = new Subject>>(); this.messagingService = MessageSender.combine( diff --git a/apps/browser/src/phishing-detection/content/phishing-detection-browser.service.ts b/apps/browser/src/phishing-detection/content/phishing-detection-browser.service.ts index 11822c5f33f..714f3e3f9b2 100644 --- a/apps/browser/src/phishing-detection/content/phishing-detection-browser.service.ts +++ b/apps/browser/src/phishing-detection/content/phishing-detection-browser.service.ts @@ -1,6 +1,4 @@ export class PhishingDetectionBrowserService { - private static knownPhishingDomains = new Set(); - static notifyUser(url: string) { const phishingDivId = "phishing-notification-bar"; const message = `${url} is a known phishing site`; diff --git a/apps/browser/src/phishing-detection/trigger-phishing-detection-script-injection.ts b/apps/browser/src/phishing-detection/trigger-phishing-detection-script-injection.ts index e585657297a..319c7e50be8 100644 --- a/apps/browser/src/phishing-detection/trigger-phishing-detection-script-injection.ts +++ b/apps/browser/src/phishing-detection/trigger-phishing-detection-script-injection.ts @@ -1,9 +1,12 @@ - import { Utils } from "@bitwarden/common/platform/misc/utils"; +import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service"; import { PhishingDetectionBrowserService } from "./content/phishing-detection-browser.service"; import { PhishingDetectionCommands } from "./phishing-detection.enum"; +const isDev = process.env.ENV === "development"; +const logService = new ConsoleLogService(isDev); + if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", loadPhishingDetectionContent); } else { @@ -25,4 +28,4 @@ async function loadPhishingDetectionContent() { } } -console.log("Phishing Detection Service loaded."); +logService.info("Phishing Detection Service loaded."); diff --git a/apps/browser/src/platform/services/phishing-detection.service.ts b/apps/browser/src/platform/services/phishing-detection.service.ts index b7de8c8125b..f389aad8234 100644 --- a/apps/browser/src/platform/services/phishing-detection.service.ts +++ b/apps/browser/src/platform/services/phishing-detection.service.ts @@ -1,4 +1,4 @@ - +import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { PhishingDetectionCommands } from "../../phishing-detection/phishing-detection.enum"; @@ -6,6 +6,15 @@ import { BrowserApi } from "../browser/browser-api"; export class PhishingDetectionService { private static knownPhishingDomains = new Set(); + static logService: LogService; + + static Initialize(logService: LogService) { + PhishingDetectionService.logService = logService; + PhishingDetectionService.setupCheckUrlListener(); + + // Initializing the data for local development + PhishingDetectionService.loadMockedData(); + } static checkUrl(url: string): boolean { const domain = Utils.getDomain(url); @@ -26,17 +35,14 @@ export class PhishingDetectionService { static setupCheckUrlListener(): void { BrowserApi.addListener(chrome.runtime.onMessage, async (message, sender, sendResponse) => { - console.log("Jimmy addListener ", { message }); if (message.command === PhishingDetectionCommands.CheckUrl) { const { activeUrl } = message; const result = { isPhishingDomain: PhishingDetectionService.checkUrl(activeUrl) }; - console.log("Jimmy", result); + + PhishingDetectionService.logService.debug("CheckUrl handler", { result, message }); sendResponse(result); } }); } } - -// Initializing the data for local development -PhishingDetectionService.loadMockedData();