From e5c5bf63cab1bbd48bf9f2219cb88d97517c8b79 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Fri, 26 Sep 2025 17:02:39 +0200 Subject: [PATCH] [deps] Platform: Update @types/chrome to v0.1.0 (#15697) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [deps] Platform: Update @types/chrome to v0.1.0 * Fix typing * Fix other build errors * Fix strict compile * Update pkg and fix remaining type errors --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Daniel GarcĂ­a --- .../overlay-notifications.background.ts | 2 +- .../auto-submit-login.background.spec.ts | 20 ++++---- .../auto-submit-login.background.ts | 29 ++++++----- .../overlay-notifications.background.spec.ts | 22 ++++----- .../overlay-notifications.background.ts | 27 +++++++---- .../background/overlay.background.spec.ts | 4 +- .../autofill/background/overlay.background.ts | 2 +- .../autofill/background/tabs.background.ts | 2 +- .../background/web-request.background.ts | 26 +++++----- .../fido2/background/fido2.background.ts | 5 +- .../content/fido2-content-script.spec.ts | 6 ++- .../src/autofill/spec/testing-utils.ts | 8 ++-- .../browser/src/background/idle.background.ts | 2 +- .../services/phishing-detection.service.ts | 4 +- .../services/phishing-detection.types.ts | 2 +- ...r-api.register-content-scripts-polyfill.ts | 48 ++++++++++++------- .../src/platform/browser/browser-api.spec.ts | 8 ++-- .../src/platform/browser/browser-api.ts | 18 ++++--- .../chrome-storage-api.service.spec.ts | 10 ++-- .../browser-script-injector.service.spec.ts | 5 +- .../browser-script-injector.service.ts | 6 +-- .../browser-platform-utils.service.spec.ts | 4 +- .../browser-system-notification.service.ts | 3 +- apps/browser/test.setup.ts | 1 + package-lock.json | 8 ++-- package.json | 2 +- 26 files changed, 157 insertions(+), 117 deletions(-) diff --git a/apps/browser/src/autofill/background/abstractions/overlay-notifications.background.ts b/apps/browser/src/autofill/background/abstractions/overlay-notifications.background.ts index 71452ec975..a70ffe2531 100644 --- a/apps/browser/src/autofill/background/abstractions/overlay-notifications.background.ts +++ b/apps/browser/src/autofill/background/abstractions/overlay-notifications.background.ts @@ -19,7 +19,7 @@ export type LoginSecurityTaskInfo = { export type WebsiteOriginsWithFields = Map>; -export type ActiveFormSubmissionRequests = Set; +export type ActiveFormSubmissionRequests = Set; export type ModifyLoginCipherFormData = { uri: string; diff --git a/apps/browser/src/autofill/background/auto-submit-login.background.spec.ts b/apps/browser/src/autofill/background/auto-submit-login.background.spec.ts index 373354b4c5..82a907a9e4 100644 --- a/apps/browser/src/autofill/background/auto-submit-login.background.spec.ts +++ b/apps/browser/src/autofill/background/auto-submit-login.background.spec.ts @@ -110,11 +110,11 @@ describe("AutoSubmitLoginBackground", () => { }); describe("when the AutomaticAppLogIn policy is valid and active", () => { - let webRequestDetails: chrome.webRequest.WebRequestBodyDetails; + let webRequestDetails: chrome.webRequest.WebRequestDetails; describe("starting the auto-submit login workflow", () => { beforeEach(async () => { - webRequestDetails = mock({ + webRequestDetails = mock({ initiator: validIpdUrl1, url: validAutoSubmitUrl, type: "main_frame", @@ -196,7 +196,7 @@ describe("AutoSubmitLoginBackground", () => { describe("cancelling an active auto-submit login workflow", () => { beforeEach(async () => { - webRequestDetails = mock({ + webRequestDetails = mock({ initiator: validIpdUrl1, url: validAutoSubmitUrl, type: "main_frame", @@ -280,7 +280,7 @@ describe("AutoSubmitLoginBackground", () => { }); describe("requests that occur within a sub-frame", () => { - const webRequestDetails = mock({ + const webRequestDetails = mock({ url: validAutoSubmitUrl, frameId: 1, }); @@ -324,7 +324,7 @@ describe("AutoSubmitLoginBackground", () => { it("updates the most recent idp host when a tab is activated", async () => { jest.spyOn(BrowserApi, "getTab").mockResolvedValue(newTab); - triggerTabOnActivatedEvent(mock({ tabId: newTabId })); + triggerTabOnActivatedEvent(mock({ tabId: newTabId })); await flushPromises(); expect(autoSubmitLoginBackground["mostRecentIdpHost"]).toStrictEqual({ @@ -336,7 +336,7 @@ describe("AutoSubmitLoginBackground", () => { it("updates the most recent id host when a tab is updated", () => { triggerTabOnUpdatedEvent( newTabId, - mock({ url: validIpdUrl1 }), + mock({ url: validIpdUrl1 }), newTab, ); @@ -389,7 +389,7 @@ describe("AutoSubmitLoginBackground", () => { tabId: newTabId, }; - triggerTabOnRemovedEvent(newTabId, mock()); + triggerTabOnRemovedEvent(newTabId, mock()); expect(autoSubmitLoginBackground["currentAutoSubmitHostData"]).toStrictEqual({}); }); @@ -403,14 +403,14 @@ describe("AutoSubmitLoginBackground", () => { tabId: tabId, }; triggerWebRequestOnBeforeRedirectEvent( - mock({ + mock({ url: validIpdUrl1, redirectUrl: validIpdUrl2, frameId: 0, }), ); triggerWebRequestOnBeforeRedirectEvent( - mock({ + mock({ url: validIpdUrl2, redirectUrl: validAutoSubmitUrl, frameId: 0, @@ -418,7 +418,7 @@ describe("AutoSubmitLoginBackground", () => { ); triggerWebRequestOnBeforeRequestEvent( - mock({ + mock({ tabId: tabId, url: `https://${validAutoSubmitHost}`, initiator: null, diff --git a/apps/browser/src/autofill/background/auto-submit-login.background.ts b/apps/browser/src/autofill/background/auto-submit-login.background.ts index dfdfa0f4d6..f593fab251 100644 --- a/apps/browser/src/autofill/background/auto-submit-login.background.ts +++ b/apps/browser/src/autofill/background/auto-submit-login.background.ts @@ -161,7 +161,9 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr * * @param details - The details of the request. */ - private handleOnBeforeRequest = (details: chrome.webRequest.WebRequestBodyDetails) => { + private handleOnBeforeRequest = ( + details: chrome.webRequest.OnBeforeRequestDetails, + ): undefined => { const requestInitiator = this.getRequestInitiator(details); const isValidInitiator = this.isValidInitiator(requestInitiator); @@ -191,7 +193,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr * @param isValidInitiator - A flag indicating if the initiator of the request is valid. */ private postRequestEncounteredAfterSubmission = ( - details: chrome.webRequest.WebRequestBodyDetails, + details: chrome.webRequest.OnBeforeRequestDetails, isValidInitiator: boolean, ) => { return details.method === "POST" && this.validAutoSubmitHosts.size > 0 && isValidInitiator; @@ -205,7 +207,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr * @param isValidInitiator - A flag indicating if the initiator of the request is valid. */ private requestRedirectsToInvalidHost = ( - details: chrome.webRequest.WebRequestBodyDetails, + details: chrome.webRequest.OnBeforeRequestDetails, isValidInitiator: boolean, ) => { return ( @@ -221,7 +223,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr * * @param details - The details of the request. */ - private setupAutoSubmitFlow = (details: chrome.webRequest.WebRequestBodyDetails) => { + private setupAutoSubmitFlow = (details: chrome.webRequest.OnBeforeRequestDetails) => { if (this.isRequestInMainFrame(details)) { this.currentAutoSubmitHostData = { url: details.url, @@ -288,7 +290,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr * @param details - The details of the request. */ private handleWebRequestOnBeforeRedirect = ( - details: chrome.webRequest.WebRedirectionResponseDetails, + details: chrome.webRequest.OnBeforeRedirectDetails, ) => { if (this.isRequestInMainFrame(details) && this.urlContainsAutoSubmitHash(details.redirectUrl)) { this.validAutoSubmitHosts.add(this.getUrlHost(details.redirectUrl)); @@ -354,7 +356,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr */ private disableAutoSubmitFlow = async ( requestInitiator: string, - details: chrome.webRequest.WebRequestBodyDetails, + details: chrome.webRequest.OnBeforeRequestDetails, ) => { if (this.isValidAutoSubmitHost(requestInitiator)) { this.removeUrlFromAutoSubmitHosts(requestInitiator); @@ -390,7 +392,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr * @param initiator - The initiator of the request. */ private shouldRouteTriggerAutoSubmit = ( - details: chrome.webRequest.ResourceRequest, + details: chrome.webRequest.OnBeforeRequestDetails, initiator: string, ) => { if (this.isRequestInMainFrame(details)) { @@ -449,7 +451,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr * * @param details - The details of the request. */ - private getRequestInitiator = (details: chrome.webRequest.ResourceRequest) => { + private getRequestInitiator = (details: chrome.webRequest.OnBeforeRequestDetails) => { if (!this.isSafariBrowser) { return details.initiator || (details as browser.webRequest._OnBeforeRequestDetails).originUrl; } @@ -470,7 +472,12 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr * * @param details - The details of the request. */ - private isRequestInMainFrame = (details: chrome.webRequest.ResourceRequest) => { + private isRequestInMainFrame = ( + details: SetPartial< + chrome.webRequest.WebRequestDetails, + "documentId" | "documentLifecycle" | "frameType" + >, + ) => { if (this.isSafariBrowser) { return details.frameId === 0; } @@ -545,7 +552,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr * * @param activeInfo - The active tab information. */ - private handleSafariTabOnActivated = async (activeInfo: chrome.tabs.TabActiveInfo) => { + private handleSafariTabOnActivated = async (activeInfo: chrome.tabs.OnActivatedInfo) => { if (activeInfo.tabId < 0) { return; } @@ -562,7 +569,7 @@ export class AutoSubmitLoginBackground implements AutoSubmitLoginBackgroundAbstr * @param tabId - The tab ID associated with the URL. * @param changeInfo - The change information of the tab. */ - private handleSafariTabOnUpdated = (tabId: number, changeInfo: chrome.tabs.TabChangeInfo) => { + private handleSafariTabOnUpdated = (tabId: number, changeInfo: chrome.tabs.OnUpdatedInfo) => { if (changeInfo) { this.setMostRecentIdpHost(changeInfo.url, tabId); } diff --git a/apps/browser/src/autofill/background/overlay-notifications.background.spec.ts b/apps/browser/src/autofill/background/overlay-notifications.background.spec.ts index cf317de4fd..c596a1ba77 100644 --- a/apps/browser/src/autofill/background/overlay-notifications.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay-notifications.background.spec.ts @@ -385,7 +385,7 @@ describe("OverlayNotificationsBackground", () => { it("ignores requests that are not part of an active form submission", async () => { triggerWebRequestOnCompletedEvent( - mock({ + mock({ url: sender.url, tabId: sender.tab.id, requestId: "123345", @@ -409,7 +409,7 @@ describe("OverlayNotificationsBackground", () => { await flushPromises(); triggerWebRequestOnCompletedEvent( - mock({ + mock({ url: sender.url, tabId: sender.tab.id, requestId, @@ -438,7 +438,7 @@ describe("OverlayNotificationsBackground", () => { await flushPromises(); triggerWebRequestOnCompletedEvent( - mock({ + mock({ url: sender.url, tabId: sender.tab.id, statusCode: 404, @@ -492,7 +492,7 @@ describe("OverlayNotificationsBackground", () => { ); }); triggerWebRequestOnCompletedEvent( - mock({ + mock({ url: sender.url, tabId: sender.tab.id, requestId, @@ -541,7 +541,7 @@ describe("OverlayNotificationsBackground", () => { }); triggerWebRequestOnCompletedEvent( - mock({ + mock({ url: sender.url, tabId: sender.tab.id, requestId, @@ -643,7 +643,7 @@ describe("OverlayNotificationsBackground", () => { }); it("clears all associated data with a removed tab", () => { - triggerTabOnRemovedEvent(sender.tab.id, mock()); + triggerTabOnRemovedEvent(sender.tab.id, mock()); expect(overlayNotificationsBackground["websiteOriginsWithFields"].size).toBe(0); }); @@ -652,7 +652,7 @@ describe("OverlayNotificationsBackground", () => { it("skips clearing the website origins if the changeInfo does not contain a `loading` status", () => { triggerTabOnUpdatedEvent( sender.tab.id, - mock({ status: "complete" }), + mock({ status: "complete" }), mock({ status: "complete" }), ); @@ -662,7 +662,7 @@ describe("OverlayNotificationsBackground", () => { it("skips clearing the website origins if the changeInfo does not contain a url", () => { triggerTabOnUpdatedEvent( sender.tab.id, - mock({ status: "loading", url: "" }), + mock({ status: "loading", url: "" }), mock({ status: "loading" }), ); @@ -672,7 +672,7 @@ describe("OverlayNotificationsBackground", () => { it("skips clearing the website origins if the tab does not contain known website origins", () => { triggerTabOnUpdatedEvent( 199, - mock({ status: "loading", url: "https://example.com" }), + mock({ status: "loading", url: "https://example.com" }), mock({ status: "loading", id: 199 }), ); @@ -682,7 +682,7 @@ describe("OverlayNotificationsBackground", () => { it("skips clearing the website origins if the changeInfo's url is present as part of the know website origin match patterns", () => { triggerTabOnUpdatedEvent( sender.tab.id, - mock({ + mock({ status: "loading", url: "https://subdomain.example.com", }), @@ -695,7 +695,7 @@ describe("OverlayNotificationsBackground", () => { it("clears all associated data with a tab that is entering a `loading` state", () => { triggerTabOnUpdatedEvent( sender.tab.id, - mock({ status: "loading" }), + mock({ status: "loading" }), mock({ status: "loading" }), ); diff --git a/apps/browser/src/autofill/background/overlay-notifications.background.ts b/apps/browser/src/autofill/background/overlay-notifications.background.ts index e7126a57e9..4657dfb6d1 100644 --- a/apps/browser/src/autofill/background/overlay-notifications.background.ts +++ b/apps/browser/src/autofill/background/overlay-notifications.background.ts @@ -228,7 +228,9 @@ export class OverlayNotificationsBackground implements OverlayNotificationsBackg * * @param details - The details of the web request */ - private handleOnBeforeRequestEvent = (details: chrome.webRequest.WebRequestDetails) => { + private handleOnBeforeRequestEvent = ( + details: chrome.webRequest.OnBeforeRequestDetails, + ): undefined => { if (this.isPostSubmissionFormRedirection(details)) { this.setupNotificationInitTrigger( details.tabId, @@ -275,7 +277,7 @@ export class OverlayNotificationsBackground implements OverlayNotificationsBackg * * @param details - The details of the web request */ - private isPostSubmissionFormRedirection = (details: chrome.webRequest.WebRequestDetails) => { + private isPostSubmissionFormRedirection = (details: chrome.webRequest.OnBeforeRequestDetails) => { return ( details.method?.toUpperCase() === "GET" && this.activeFormSubmissionRequests.has(details.requestId) && @@ -289,7 +291,7 @@ export class OverlayNotificationsBackground implements OverlayNotificationsBackg * * @param details - The details of the web request */ - private isValidFormSubmissionRequest = (details: chrome.webRequest.WebRequestDetails) => { + private isValidFormSubmissionRequest = (details: chrome.webRequest.OnBeforeRequestDetails) => { return ( !this.requestHostIsInvalid(details) && this.formSubmissionRequestMethods.has(details.method?.toUpperCase()) @@ -325,7 +327,7 @@ export class OverlayNotificationsBackground implements OverlayNotificationsBackg * * @param details - The details of the web response */ - private handleOnCompletedRequestEvent = async (details: chrome.webRequest.WebResponseDetails) => { + private handleOnCompletedRequestEvent = async (details: chrome.webRequest.OnCompletedDetails) => { if ( this.requestHostIsInvalid(details) || !this.activeFormSubmissionRequests.has(details.requestId) @@ -382,8 +384,8 @@ export class OverlayNotificationsBackground implements OverlayNotificationsBackg * @param modifyLoginData - The modified login form data */ private delayNotificationInitUntilTabIsComplete = async ( - tabId: chrome.webRequest.ResourceRequest["tabId"], - requestId: chrome.webRequest.ResourceRequest["requestId"], + tabId: chrome.webRequest.WebRequestDetails["tabId"], + requestId: chrome.webRequest.WebRequestDetails["requestId"], modifyLoginData: ModifyLoginCipherFormData, ) => { const handleWebNavigationOnCompleted = async () => { @@ -403,7 +405,7 @@ export class OverlayNotificationsBackground implements OverlayNotificationsBackg * @param tab - The tab details */ private processNotifications = async ( - requestId: chrome.webRequest.ResourceRequest["requestId"], + requestId: chrome.webRequest.WebRequestDetails["requestId"], modifyLoginData: ModifyLoginCipherFormData, tab: chrome.tabs.Tab, config: { skippable: NotificationType[] } = { skippable: [] }, @@ -477,7 +479,7 @@ export class OverlayNotificationsBackground implements OverlayNotificationsBackg * @param tab - The tab details */ private clearCompletedWebRequest = ( - requestId: chrome.webRequest.ResourceRequest["requestId"], + requestId: chrome.webRequest.WebRequestDetails["requestId"], tabId: chrome.tabs.Tab["id"], ) => { this.activeFormSubmissionRequests.delete(requestId); @@ -492,7 +494,12 @@ export class OverlayNotificationsBackground implements OverlayNotificationsBackg * * @param details - The details of the web request */ - private requestHostIsInvalid = (details: chrome.webRequest.ResourceRequest) => { + private requestHostIsInvalid = ( + details: SetPartial< + chrome.webRequest.WebRequestDetails, + "documentId" | "documentLifecycle" | "frameType" + >, + ) => { return !details.url?.startsWith("http") || details.tabId < 0; }; @@ -553,7 +560,7 @@ export class OverlayNotificationsBackground implements OverlayNotificationsBackg * @param tabId - The id of the tab that was updated * @param changeInfo - The change info of the tab */ - private handleTabUpdated = (tabId: number, changeInfo: chrome.tabs.TabChangeInfo) => { + private handleTabUpdated = (tabId: number, changeInfo: chrome.tabs.OnUpdatedInfo) => { if (changeInfo.status !== "loading" || !changeInfo.url) { return; } diff --git a/apps/browser/src/autofill/background/overlay.background.spec.ts b/apps/browser/src/autofill/background/overlay.background.spec.ts index 696454b424..47a5e8fec4 100644 --- a/apps/browser/src/autofill/background/overlay.background.spec.ts +++ b/apps/browser/src/autofill/background/overlay.background.spec.ts @@ -3371,7 +3371,7 @@ describe("OverlayBackground", () => { }); await flushPromises(); triggerWebRequestOnCompletedEvent( - mock({ + mock({ statusCode: 401, }), ); @@ -3391,7 +3391,7 @@ describe("OverlayBackground", () => { }); await flushPromises(); triggerWebRequestOnCompletedEvent( - mock({ + mock({ statusCode: 200, }), ); diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 5da00cfaff..35585d5886 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -1238,7 +1238,7 @@ export class OverlayBackground implements OverlayBackgroundInterface { * @param details - The web request details */ private handlePasskeyAuthenticationOnCompleted = ( - details: chrome.webRequest.WebResponseCacheDetails, + details: chrome.webRequest.OnCompletedDetails, ) => { chrome.webRequest.onCompleted.removeListener(this.handlePasskeyAuthenticationOnCompleted); diff --git a/apps/browser/src/autofill/background/tabs.background.ts b/apps/browser/src/autofill/background/tabs.background.ts index cd2c1595d6..b76997c0ae 100644 --- a/apps/browser/src/autofill/background/tabs.background.ts +++ b/apps/browser/src/autofill/background/tabs.background.ts @@ -81,7 +81,7 @@ export default class TabsBackground { */ private handleTabOnUpdated = async ( tabId: number, - changeInfo: chrome.tabs.TabChangeInfo, + changeInfo: chrome.tabs.OnUpdatedInfo, tab: chrome.tabs.Tab, ) => { if (this.focusedWindowId > 0 && tab.windowId !== this.focusedWindowId) { diff --git a/apps/browser/src/autofill/background/web-request.background.ts b/apps/browser/src/autofill/background/web-request.background.ts index 22e10a3dd0..5c02f2df34 100644 --- a/apps/browser/src/autofill/background/web-request.background.ts +++ b/apps/browser/src/autofill/background/web-request.background.ts @@ -26,7 +26,10 @@ export default class WebRequestBackground { startListening() { this.webRequest.onAuthRequired.addListener( - async (details, callback) => { + (async ( + details: chrome.webRequest.OnAuthRequiredDetails, + callback: (response: chrome.webRequest.BlockingResponse) => void, + ) => { if (!details.url || this.pendingAuthRequests.has(details.requestId)) { if (callback) { callback(null); @@ -42,7 +45,7 @@ export default class WebRequestBackground { } else { await this.resolveAuthCredentials(details.url, callback, callback); } - }, + }) as any, { urls: ["http://*/*", "https://*/*"] }, [this.isFirefox ? "blocking" : "asyncBlocking"], ); @@ -50,16 +53,17 @@ export default class WebRequestBackground { this.webRequest.onCompleted.addListener((details) => this.completeAuthRequest(details), { urls: ["http://*/*"], }); - this.webRequest.onErrorOccurred.addListener( - (details: any) => this.completeAuthRequest(details), - { - urls: ["http://*/*"], - }, - ); + this.webRequest.onErrorOccurred.addListener((details) => this.completeAuthRequest(details), { + urls: ["http://*/*"], + }); } - // eslint-disable-next-line - private async resolveAuthCredentials(domain: string, success: Function, error: Function) { + private async resolveAuthCredentials( + domain: string, + success: (response: chrome.webRequest.BlockingResponse) => void, + // eslint-disable-next-line + error: Function, + ) { const activeUserId = await firstValueFrom( this.accountService.activeAccount$.pipe(getOptionalUserId), ); @@ -97,7 +101,7 @@ export default class WebRequestBackground { } } - private completeAuthRequest(details: chrome.webRequest.WebResponseCacheDetails) { + private completeAuthRequest(details: chrome.webRequest.WebRequestDetails) { this.pendingAuthRequests.delete(details.requestId); } } diff --git a/apps/browser/src/autofill/fido2/background/fido2.background.ts b/apps/browser/src/autofill/fido2/background/fido2.background.ts index 788c98ca85..22ee4a1822 100644 --- a/apps/browser/src/autofill/fido2/background/fido2.background.ts +++ b/apps/browser/src/autofill/fido2/background/fido2.background.ts @@ -218,7 +218,10 @@ export class Fido2Background implements Fido2BackgroundInterface { tabId: tab.id, injectDetails: { frame: "all_frames", ...this.sharedInjectionDetails }, mv2Details: { file: await this.getFido2PageScriptAppendFileName() }, - mv3Details: { file: Fido2ContentScript.PageScript, world: "MAIN" }, + mv3Details: { + file: Fido2ContentScript.PageScript, + world: chrome.scripting.ExecutionWorld.MAIN, + }, }); void this.scriptInjectorService.inject({ diff --git a/apps/browser/src/autofill/fido2/content/fido2-content-script.spec.ts b/apps/browser/src/autofill/fido2/content/fido2-content-script.spec.ts index af7344beb6..f50e541f67 100644 --- a/apps/browser/src/autofill/fido2/content/fido2-content-script.spec.ts +++ b/apps/browser/src/autofill/fido2/content/fido2-content-script.spec.ts @@ -75,7 +75,7 @@ describe("Fido2 Content Script", () => { data: mock(), }); const mockResult = { credentialId: "mock" } as CreateCredentialResult; - jest.spyOn(chrome.runtime, "sendMessage").mockResolvedValue(mockResult); + (jest.spyOn(chrome.runtime, "sendMessage") as jest.Mock).mockResolvedValue(mockResult); // FIXME: Remove when updating file. Eslint update // eslint-disable-next-line @typescript-eslint/no-require-imports @@ -167,7 +167,9 @@ describe("Fido2 Content Script", () => { data: mock(), }); const abortController = new AbortController(); - jest.spyOn(chrome.runtime, "sendMessage").mockResolvedValue({ error: errorMessage }); + (jest.spyOn(chrome.runtime, "sendMessage") as jest.Mock).mockResolvedValue({ + error: errorMessage, + }); // FIXME: Remove when updating file. Eslint update // eslint-disable-next-line @typescript-eslint/no-require-imports diff --git a/apps/browser/src/autofill/spec/testing-utils.ts b/apps/browser/src/autofill/spec/testing-utils.ts index 1a3f3a5223..0082f022fb 100644 --- a/apps/browser/src/autofill/spec/testing-utils.ts +++ b/apps/browser/src/autofill/spec/testing-utils.ts @@ -80,7 +80,7 @@ export function triggerWindowOnFocusedChangedEvent(windowId: number) { ); } -export function triggerTabOnActivatedEvent(activeInfo: chrome.tabs.TabActiveInfo) { +export function triggerTabOnActivatedEvent(activeInfo: chrome.tabs.OnActivatedInfo) { (chrome.tabs.onActivated.addListener as unknown as jest.SpyInstance).mock.calls.forEach( (call) => { const callback = call[0]; @@ -98,7 +98,7 @@ export function triggerTabOnReplacedEvent(addedTabId: number, removedTabId: numb export function triggerTabOnUpdatedEvent( tabId: number, - changeInfo: chrome.tabs.TabChangeInfo, + changeInfo: chrome.tabs.OnUpdatedInfo, tab: chrome.tabs.Tab, ) { (chrome.tabs.onUpdated.addListener as unknown as jest.SpyInstance).mock.calls.forEach((call) => { @@ -107,7 +107,7 @@ export function triggerTabOnUpdatedEvent( }); } -export function triggerTabOnRemovedEvent(tabId: number, removeInfo: chrome.tabs.TabRemoveInfo) { +export function triggerTabOnRemovedEvent(tabId: number, removeInfo: chrome.tabs.OnRemovedInfo) { (chrome.tabs.onRemoved.addListener as unknown as jest.SpyInstance).mock.calls.forEach((call) => { const callback = call[0]; callback(tabId, removeInfo); @@ -165,7 +165,7 @@ export function triggerWebRequestOnBeforeRedirectEvent( }); } -export function triggerWebRequestOnCompletedEvent(details: chrome.webRequest.WebResponseDetails) { +export function triggerWebRequestOnCompletedEvent(details: chrome.webRequest.OnCompletedDetails) { (chrome.webRequest.onCompleted.addListener as unknown as jest.SpyInstance).mock.calls.forEach( (call) => { const callback = call[0]; diff --git a/apps/browser/src/background/idle.background.ts b/apps/browser/src/background/idle.background.ts index 81a869917a..2de4b48a9c 100644 --- a/apps/browser/src/background/idle.background.ts +++ b/apps/browser/src/background/idle.background.ts @@ -46,7 +46,7 @@ export default class IdleBackground { if (this.idle.onStateChanged) { this.idle.onStateChanged.addListener( - async (newState: chrome.idle.IdleState | browser.idle.IdleState) => { + async (newState: `${chrome.idle.IdleState}` | browser.idle.IdleState) => { if (newState === "locked") { // Need to check if any of the current users have their timeout set to `onLocked` const allUsers = await firstValueFrom(this.accountService.accounts$); 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 dd7cf083a0..1497ac96db 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 @@ -230,7 +230,7 @@ export class PhishingDetectionService { */ private static async _processNavigation( tabId: number, - changeInfo: chrome.tabs.TabChangeInfo, + changeInfo: chrome.tabs.OnUpdatedInfo, tab: chrome.tabs.Tab, ): Promise { if (changeInfo.status !== "complete" || !tab.url) { @@ -253,7 +253,7 @@ export class PhishingDetectionService { private static _handleNavigationEvent( tabId: number, - changeInfo: chrome.tabs.TabChangeInfo, + changeInfo: chrome.tabs.OnUpdatedInfo, tab: chrome.tabs.Tab, ): boolean { this._navigationEventsSubject.next({ tabId, changeInfo, tab }); diff --git a/apps/browser/src/dirt/phishing-detection/services/phishing-detection.types.ts b/apps/browser/src/dirt/phishing-detection/services/phishing-detection.types.ts index 86fe61909c..2179361624 100644 --- a/apps/browser/src/dirt/phishing-detection/services/phishing-detection.types.ts +++ b/apps/browser/src/dirt/phishing-detection/services/phishing-detection.types.ts @@ -30,6 +30,6 @@ export type CaughtPhishingDomain = { export type PhishingDetectionNavigationEvent = { tabId: number; - changeInfo: chrome.tabs.TabChangeInfo; + changeInfo: chrome.tabs.OnUpdatedInfo; tab: chrome.tabs.Tab; }; diff --git a/apps/browser/src/platform/browser/browser-api.register-content-scripts-polyfill.ts b/apps/browser/src/platform/browser/browser-api.register-content-scripts-polyfill.ts index 0b0dd21824..a8e7b7eeb3 100644 --- a/apps/browser/src/platform/browser/browser-api.register-content-scripts-polyfill.ts +++ b/apps/browser/src/platform/browser/browser-api.register-content-scripts-polyfill.ts @@ -141,8 +141,24 @@ function buildRegisterContentScriptsPolyfill() { return [possibleArray]; } - function arrayOrUndefined(value?: number) { - return value === undefined ? undefined : [value]; + function createTarget( + tabId: number, + frameId: number | undefined, + allFrames: boolean, + ): chrome.scripting.InjectionTarget { + if (frameId === undefined) { + return { + tabId, + frameIds: undefined, + allFrames: allFrames, + }; + } else { + return { + tabId, + frameIds: [frameId], + allFrames: undefined, + }; + } } async function insertCSS( @@ -170,15 +186,17 @@ function buildRegisterContentScriptsPolyfill() { } if (gotScripting) { - return chrome.scripting.insertCSS({ - target: { - tabId, - frameIds: arrayOrUndefined(frameId), - allFrames: frameId === undefined ? allFrames : undefined, - }, - files: "file" in content ? [content.file] : undefined, - css: "code" in content ? content.code : undefined, - }); + if ("file" in content) { + return chrome.scripting.insertCSS({ + target: createTarget(tabId, frameId, allFrames), + files: [content.file], + }); + } else { + return chrome.scripting.insertCSS({ + target: createTarget(tabId, frameId, allFrames), + css: content.code, + }); + } } return chromeProxy.tabs.insertCSS(tabId, { @@ -226,11 +244,7 @@ function buildRegisterContentScriptsPolyfill() { if (gotScripting) { assertNoCode(normalizedFiles); const injection = chrome.scripting.executeScript({ - target: { - tabId, - frameIds: arrayOrUndefined(frameId), - allFrames: frameId === undefined ? allFrames : undefined, - }, + target: createTarget(tabId, frameId, allFrames), files: normalizedFiles.map(({ file }: { file: string }) => file), }); @@ -397,7 +411,7 @@ function buildRegisterContentScriptsPolyfill() { }; const tabListener = async ( tabId: number, - { status }: chrome.tabs.TabChangeInfo, + { status }: chrome.tabs.OnUpdatedInfo, { url }: chrome.tabs.Tab, ) => { if (status === "loading" && url) { diff --git a/apps/browser/src/platform/browser/browser-api.spec.ts b/apps/browser/src/platform/browser/browser-api.spec.ts index 49d3e8e1ce..f7561b2b50 100644 --- a/apps/browser/src/platform/browser/browser-api.spec.ts +++ b/apps/browser/src/platform/browser/browser-api.spec.ts @@ -375,7 +375,7 @@ describe("BrowserApi", () => { describe("executeScriptInTab", () => { it("calls to the extension api to execute a script within the give tabId", async () => { const tabId = 1; - const injectDetails = mock(); + const injectDetails = mock(); jest.spyOn(BrowserApi, "manifestVersion", "get").mockReturnValue(2); (chrome.tabs.executeScript as jest.Mock).mockImplementation( (tabId, injectDetails, callback) => callback(executeScriptResult), @@ -393,7 +393,7 @@ describe("BrowserApi", () => { it("calls the manifest v3 scripting API if the extension manifest is for v3", async () => { const tabId = 1; - const injectDetails = mock({ + const injectDetails = mock({ file: "file.js", allFrames: true, runAt: "document_start", @@ -419,7 +419,7 @@ describe("BrowserApi", () => { it("injects the script into a specified frameId when the extension is built for manifest v3", async () => { const tabId = 1; const frameId = 2; - const injectDetails = mock({ + const injectDetails = mock({ file: "file.js", allFrames: true, runAt: "document_start", @@ -443,7 +443,7 @@ describe("BrowserApi", () => { it("injects the script into the MAIN world context when injecting a script for manifest v3", async () => { const tabId = 1; - const injectDetails = mock({ + const injectDetails = mock({ file: null, allFrames: true, runAt: "document_start", diff --git a/apps/browser/src/platform/browser/browser-api.ts b/apps/browser/src/platform/browser/browser-api.ts index 339fd71b07..8a3dbafc5c 100644 --- a/apps/browser/src/platform/browser/browser-api.ts +++ b/apps/browser/src/platform/browser/browser-api.ts @@ -685,29 +685,27 @@ export class BrowserApi { */ static executeScriptInTab( tabId: number, - details: chrome.tabs.InjectDetails, + details: chrome.extensionTypes.InjectDetails, scriptingApiDetails?: { world: chrome.scripting.ExecutionWorld; }, ): Promise { if (BrowserApi.isManifestVersion(3)) { - const target: chrome.scripting.InjectionTarget = { - tabId, - }; + let target: chrome.scripting.InjectionTarget; if (typeof details.frameId === "number") { - target.frameIds = [details.frameId]; - } - - if (!target.frameIds?.length && details.allFrames) { - target.allFrames = details.allFrames; + target = { tabId, frameIds: [details.frameId] }; + } else if (details.allFrames) { + target = { tabId, allFrames: true }; + } else { + target = { tabId }; } return chrome.scripting.executeScript({ target, files: details.file ? [details.file] : null, injectImmediately: details.runAt === "document_start", - world: scriptingApiDetails?.world || "ISOLATED", + world: scriptingApiDetails?.world || chrome.scripting.ExecutionWorld.ISOLATED, }); } diff --git a/apps/browser/src/platform/services/abstractions/chrome-storage-api.service.spec.ts b/apps/browser/src/platform/services/abstractions/chrome-storage-api.service.spec.ts index ac8a01375f..c1d0aa235f 100644 --- a/apps/browser/src/platform/services/abstractions/chrome-storage-api.service.spec.ts +++ b/apps/browser/src/platform/services/abstractions/chrome-storage-api.service.spec.ts @@ -52,7 +52,7 @@ describe("ChromeStorageApiService", () => { }); afterEach(() => { - chrome.runtime.lastError = undefined; + (chrome.runtime.lastError as any) = undefined; }); it("uses `objToStore` to prepare a value for set", async () => { @@ -80,7 +80,7 @@ describe("ChromeStorageApiService", () => { it("translates chrome.runtime.lastError to promise rejection", async () => { setMock.mockImplementation((data, callback) => { - chrome.runtime.lastError = new Error("Test Error"); + (chrome.runtime.lastError as any) = new Error("Test Error"); callback(); }); @@ -101,7 +101,7 @@ describe("ChromeStorageApiService", () => { }); afterEach(() => { - chrome.runtime.lastError = undefined; + (chrome.runtime.lastError as any) = undefined; }); it("returns a stored value when it is serialized", async () => { @@ -132,9 +132,9 @@ describe("ChromeStorageApiService", () => { it("translates chrome.runtime.lastError to promise rejection", async () => { getMock.mockImplementation((key, callback) => { - chrome.runtime.lastError = new Error("Test Error"); + (chrome.runtime.lastError as any) = new Error("Test Error"); callback(); - chrome.runtime.lastError = undefined; + (chrome.runtime.lastError as any) = undefined; }); await expect(async () => await service.get("test")).rejects.toThrow("Test Error"); diff --git a/apps/browser/src/platform/services/browser-script-injector.service.spec.ts b/apps/browser/src/platform/services/browser-script-injector.service.spec.ts index 21f6debc02..e4abea1d71 100644 --- a/apps/browser/src/platform/services/browser-script-injector.service.spec.ts +++ b/apps/browser/src/platform/services/browser-script-injector.service.spec.ts @@ -41,7 +41,10 @@ describe("ScriptInjectorService", () => { const mv2SpecificFile = "content/autofill-init-mv2.js"; const mv2Details = { file: mv2SpecificFile }; const mv3SpecificFile = "content/autofill-init-mv3.js"; - const mv3Details: Mv3ScriptInjectionDetails = { file: mv3SpecificFile, world: "MAIN" }; + const mv3Details: Mv3ScriptInjectionDetails = { + file: mv3SpecificFile, + world: chrome.scripting.ExecutionWorld.MAIN, + }; const sharedInjectDetails: CommonScriptInjectionDetails = { runAt: "document_start", }; diff --git a/apps/browser/src/platform/services/browser-script-injector.service.ts b/apps/browser/src/platform/services/browser-script-injector.service.ts index a617f2215c..575e9ccf70 100644 --- a/apps/browser/src/platform/services/browser-script-injector.service.ts +++ b/apps/browser/src/platform/services/browser-script-injector.service.ts @@ -63,7 +63,7 @@ export class BrowserScriptInjectorService extends ScriptInjectorService { if (BrowserApi.isManifestVersion(3)) { try { await BrowserApi.executeScriptInTab(tabId, injectionDetails, { - world: mv3Details?.world ?? "ISOLATED", + world: mv3Details?.world ?? chrome.scripting.ExecutionWorld.ISOLATED, }); } catch (error) { // Swallow errors for host permissions, since this is believed to be a Manifest V3 Chrome bug @@ -112,9 +112,9 @@ export class BrowserScriptInjectorService extends ScriptInjectorService { private buildInjectionDetails( injectDetails: CommonScriptInjectionDetails, file: string, - ): chrome.tabs.InjectDetails { + ): chrome.extensionTypes.InjectDetails { const { frame, runAt } = injectDetails; - const injectionDetails: chrome.tabs.InjectDetails = { file }; + const injectionDetails: chrome.extensionTypes.InjectDetails = { file }; if (runAt) { injectionDetails.runAt = runAt; diff --git a/apps/browser/src/platform/services/platform-utils/browser-platform-utils.service.spec.ts b/apps/browser/src/platform/services/platform-utils/browser-platform-utils.service.spec.ts index 81e1008eea..61e56f08e1 100644 --- a/apps/browser/src/platform/services/platform-utils/browser-platform-utils.service.spec.ts +++ b/apps/browser/src/platform/services/platform-utils/browser-platform-utils.service.spec.ts @@ -167,7 +167,7 @@ describe("Browser Utils Service", () => { it("returns false if special error is sent", async () => { chrome.runtime.sendMessage = jest.fn().mockImplementation((message, callback) => { - chrome.runtime.lastError = new Error( + (chrome.runtime.lastError as any) = new Error( "Could not establish connection. Receiving end does not exist.", ); callback(undefined); @@ -177,7 +177,7 @@ describe("Browser Utils Service", () => { expect(isViewOpen).toBe(false); - chrome.runtime.lastError = null; + (chrome.runtime.lastError as any) = null; }); }); diff --git a/apps/browser/src/platform/system-notifications/browser-system-notification.service.ts b/apps/browser/src/platform/system-notifications/browser-system-notification.service.ts index 0eb4739ea9..b835c71185 100644 --- a/apps/browser/src/platform/system-notifications/browser-system-notification.service.ts +++ b/apps/browser/src/platform/system-notifications/browser-system-notification.service.ts @@ -46,7 +46,7 @@ export class BrowserSystemNotificationService implements SystemNotificationsServ return new Promise((resolve) => { const deviceType: DeviceType = this.platformUtilsService.getDevice(); - const options: chrome.notifications.NotificationOptions = { + const options: chrome.notifications.NotificationCreateOptions = { iconUrl: chrome.runtime.getURL("images/icon128.png"), message: createInfo.body, type: "basic", @@ -70,6 +70,7 @@ export class BrowserSystemNotificationService implements SystemNotificationsServ } async clear(clearInfo: SystemNotificationClearInfo): Promise { + // eslint-disable-next-line @typescript-eslint/no-floating-promises chrome.notifications.clear(clearInfo.id); } diff --git a/apps/browser/test.setup.ts b/apps/browser/test.setup.ts index eb635e646e..08b7287984 100644 --- a/apps/browser/test.setup.ts +++ b/apps/browser/test.setup.ts @@ -79,6 +79,7 @@ const scripting = { executeScript: jest.fn(), registerContentScripts: jest.fn(), unregisterContentScripts: jest.fn(), + ExecutionWorld: { ISOLATED: "ISOLATED", MAIN: "MAIN" }, }; const windows = { diff --git a/package-lock.json b/package-lock.json index 2ea907ec59..1b126255e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -97,7 +97,7 @@ "@storybook/test-runner": "0.22.0", "@storybook/theming": "8.6.12", "@storybook/web-components-webpack5": "8.6.12", - "@types/chrome": "0.0.306", + "@types/chrome": "0.1.12", "@types/firefox-webext-browser": "120.0.4", "@types/inquirer": "8.2.10", "@types/jest": "29.5.14", @@ -13377,9 +13377,9 @@ } }, "node_modules/@types/chrome": { - "version": "0.0.306", - "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.306.tgz", - "integrity": "sha512-95kgcqvTNcaZCXmx/kIKY6uo83IaRNT3cuPxYqlB2Iu+HzKDCP4t7TUe7KhJijTdibcvn+SzziIcfSLIlgRnhQ==", + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.1.12.tgz", + "integrity": "sha512-jEkxs9GPQHx7g49WjkA8QDNcqODbMGDuBbWQOtjiS/Wf9AiEcDmQMIAgJvC/Xi36WoCVNx584g0Dd9ThJQCAiw==", "dev": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 65ead3fffc..e94d0e9852 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@storybook/test-runner": "0.22.0", "@storybook/theming": "8.6.12", "@storybook/web-components-webpack5": "8.6.12", - "@types/chrome": "0.0.306", + "@types/chrome": "0.1.12", "@types/firefox-webext-browser": "120.0.4", "@types/inquirer": "8.2.10", "@types/jest": "29.5.14",