1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-14 07:23:45 +00:00

Update code to use Log service.

This commit is contained in:
Jimmy Vo
2025-03-17 16:08:28 -04:00
parent 92b562ca0e
commit 7ad7f638d7
4 changed files with 19 additions and 12 deletions

View File

@@ -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<Message<Record<string, unknown>>>();
this.messagingService = MessageSender.combine(

View File

@@ -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`;

View File

@@ -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.");

View File

@@ -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();