diff --git a/apps/browser/src/autofill/services/autofill.service.spec.ts b/apps/browser/src/autofill/services/autofill.service.spec.ts index 4db64f417de..7353a4a8da8 100644 --- a/apps/browser/src/autofill/services/autofill.service.spec.ts +++ b/apps/browser/src/autofill/services/autofill.service.spec.ts @@ -43,7 +43,7 @@ import { createChromeTabMock, createGenerateFillScriptOptionsMock, } from "../spec/autofill-mocks"; -import { triggerTestFailure } from "../spec/testing-utils"; +import { flushPromises, triggerTestFailure } from "../spec/testing-utils"; import { AutoFillOptions, @@ -104,6 +104,9 @@ describe("AutofillService", () => { tab2 = createChromeTabMock({ id: 2, url: "http://some-url.com" }); tab3 = createChromeTabMock({ id: 3, url: "chrome-extension://some-extension-route" }); jest.spyOn(BrowserApi, "tabsQuery").mockResolvedValueOnce([tab1, tab2]); + jest + .spyOn(BrowserApi, "getAllFrames") + .mockResolvedValue([mock({ frameId: 0 })]); jest .spyOn(autofillService, "getOverlayVisibility") .mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus); @@ -114,6 +117,7 @@ describe("AutofillService", () => { jest.spyOn(autofillService, "injectAutofillScripts"); await autofillService.loadAutofillScriptsOnInstall(); + await flushPromises(); expect(BrowserApi.tabsQuery).toHaveBeenCalledWith({}); expect(autofillService.injectAutofillScripts).toHaveBeenCalledWith(tab1, 0, false); diff --git a/apps/browser/src/autofill/services/autofill.service.ts b/apps/browser/src/autofill/services/autofill.service.ts index a7b32c077e8..4ae5f06a8d5 100644 --- a/apps/browser/src/autofill/services/autofill.service.ts +++ b/apps/browser/src/autofill/services/autofill.service.ts @@ -65,10 +65,7 @@ export default class AutofillService implements AutofillServiceInterface { */ async loadAutofillScriptsOnInstall() { BrowserApi.addListener(chrome.runtime.onConnect, this.handleInjectedScriptPortConnection); - - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.injectAutofillScriptsInAllTabs(); + void this.injectAutofillScriptsInAllTabs(); } /** @@ -2064,9 +2061,8 @@ export default class AutofillService implements AutofillServiceInterface { for (let index = 0; index < tabs.length; index++) { const tab = tabs[index]; if (tab.url?.startsWith("http")) { - chrome.webNavigation.getAllFrames({ tabId: tab.id }, (frames) => - frames.forEach((frame) => this.injectAutofillScripts(tab, frame.frameId, false)), - ); + const frames = await BrowserApi.getAllFrames({ tabId: tab.id }); + frames.forEach((frame) => this.injectAutofillScripts(tab, frame.frameId, false)); } } } diff --git a/apps/browser/src/platform/browser/browser-api.ts b/apps/browser/src/platform/browser/browser-api.ts index 4cba5a5f275..4635e869eeb 100644 --- a/apps/browser/src/platform/browser/browser-api.ts +++ b/apps/browser/src/platform/browser/browser-api.ts @@ -275,6 +275,12 @@ export class BrowserApi { return new Promise((resolve) => chrome.webNavigation.getFrame(details, resolve)); } + static async getAllFrames( + details: chrome.webNavigation.GetAllFrameDetails, + ): Promise { + return new Promise((resolve) => chrome.webNavigation.getAllFrames(details, resolve)); + } + // Keep track of all the events registered in a Safari popup so we can remove // them when the popup gets unloaded, otherwise we cause a memory leak private static trackedChromeEventListeners: [