From 3031d712e96bac6ab02dd378c57aa2da50a30db5 Mon Sep 17 00:00:00 2001 From: Jimmy Vo Date: Wed, 16 Apr 2025 15:44:16 -0400 Subject: [PATCH] [PM-19814] Use webNavigation.onCompleted for redirect to ensure that the redirect only happens when they land on the page. --- .../background/phishing-detection.service.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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 34fa8588a4a..e7a6e7b5aa1 100644 --- a/apps/browser/src/phishing-detection/background/phishing-detection.service.ts +++ b/apps/browser/src/phishing-detection/background/phishing-detection.service.ts @@ -226,19 +226,27 @@ export class PhishingDetectionService { } static setupListeners(): void { - chrome.webRequest.onCompleted.addListener( - (details: chrome.webRequest.WebRequestDetails): void => { + chrome.webNavigation.onCompleted.addListener( + (details: chrome.webNavigation.WebNavigationFramedCallbackDetails): void => { const url = new URL(details.url); + const result = PhishingDetectionService.knownPhishingDomains.has(url.hostname); - if (PhishingDetectionService.knownPhishingDomains.has(url.hostname)) { + this.logService.debug("Phishing detection check", { + details, + result, + url, + }); + + if (result) { PhishingDetectionService.RedirectToWarningPage(url.hostname, details.tabId); } }, - { urls: [""], types: ["main_frame"] }, ); } static RedirectToWarningPage(hostname: string, tabId: number) { + this.logService.debug("Redirecting to warning page."); + const phishingWarningPage = chrome.runtime.getURL( "popup/index.html#/security/phishing-warning", );