diff --git a/apps/browser/src/autofill/services/autofill.service.spec.ts b/apps/browser/src/autofill/services/autofill.service.spec.ts index fa3f7df3b7b..050c3524b62 100644 --- a/apps/browser/src/autofill/services/autofill.service.spec.ts +++ b/apps/browser/src/autofill/services/autofill.service.spec.ts @@ -125,7 +125,7 @@ describe("AutofillService", () => { tab3 = createChromeTabMock({ id: 3, url: "chrome-extension://some-extension-route" }); jest.spyOn(BrowserApi, "tabsQuery").mockResolvedValueOnce([tab1, tab2]); jest - .spyOn(BrowserApi, "getAllFrames") + .spyOn(BrowserApi, "getAllFrameDetails") .mockResolvedValue([mock({ frameId: 0 })]); jest .spyOn(autofillService, "getInlineMenuVisibility") diff --git a/apps/browser/src/autofill/services/autofill.service.ts b/apps/browser/src/autofill/services/autofill.service.ts index 7b14f24c9aa..d3bdf25d490 100644 --- a/apps/browser/src/autofill/services/autofill.service.ts +++ b/apps/browser/src/autofill/services/autofill.service.ts @@ -2094,7 +2094,7 @@ export default class AutofillService implements AutofillServiceInterface { for (let index = 0; index < tabs.length; index++) { const tab = tabs[index]; if (tab.url?.startsWith("http")) { - const frames = await BrowserApi.getAllFrames({ tabId: tab.id }); + const frames = await BrowserApi.getAllFrameDetails(tab.id); frames.forEach((frame) => this.injectAutofillScripts(tab, frame.frameId, false)); } } diff --git a/apps/browser/src/platform/browser/browser-api.spec.ts b/apps/browser/src/platform/browser/browser-api.spec.ts index 7e0c61c9d17..adf248707c2 100644 --- a/apps/browser/src/platform/browser/browser-api.spec.ts +++ b/apps/browser/src/platform/browser/browser-api.spec.ts @@ -235,6 +235,46 @@ describe("BrowserApi", () => { }); }); + describe("getFrameDetails", () => { + it("returns the frame details of the specified frame", async () => { + const tabId = 1; + const frameId = 2; + const mockFrameDetails = mock(); + chrome.webNavigation.getFrame = jest + .fn() + .mockImplementation((_details, callback) => callback(mockFrameDetails)); + + const returnFrame = await BrowserApi.getFrameDetails({ tabId, frameId }); + + expect(chrome.webNavigation.getFrame).toHaveBeenCalledWith( + { tabId, frameId }, + expect.any(Function), + ); + expect(returnFrame).toEqual(mockFrameDetails); + }); + }); + + describe("getAllFrameDetails", () => { + it("returns all sub frame details of the specified tab", async () => { + const tabId = 1; + const mockFrameDetails1 = mock(); + const mockFrameDetails2 = mock(); + chrome.webNavigation.getAllFrames = jest + .fn() + .mockImplementation((_details, callback) => + callback([mockFrameDetails1, mockFrameDetails2]), + ); + + const frames = await BrowserApi.getAllFrameDetails(tabId); + + expect(chrome.webNavigation.getAllFrames).toHaveBeenCalledWith( + { tabId }, + expect.any(Function), + ); + expect(frames).toEqual([mockFrameDetails1, mockFrameDetails2]); + }); + }); + describe("reloadExtension", () => { it("reloads the window location if the passed globalContext is for the window", () => { const windowMock = mock({ diff --git a/apps/browser/src/platform/browser/browser-api.ts b/apps/browser/src/platform/browser/browser-api.ts index eccd1e2fc75..674f785eb28 100644 --- a/apps/browser/src/platform/browser/browser-api.ts +++ b/apps/browser/src/platform/browser/browser-api.ts @@ -263,16 +263,26 @@ export class BrowserApi { ); } + /** + * Gathers the details for a specified sub-frame of a tab. + * + * @param details - The details of the frame to get. + */ static async getFrameDetails( details: chrome.webNavigation.GetFrameDetails, ): Promise { return new Promise((resolve) => chrome.webNavigation.getFrame(details, resolve)); } - static async getAllFrames( - details: chrome.webNavigation.GetAllFrameDetails, + /** + * Gets all frames associated with a tab. + * + * @param tabId - The id of the tab to get the frames for. + */ + static async getAllFrameDetails( + tabId: chrome.tabs.Tab["id"], ): Promise { - return new Promise((resolve) => chrome.webNavigation.getAllFrames(details, resolve)); + return new Promise((resolve) => chrome.webNavigation.getAllFrames({ tabId }, resolve)); } // Keep track of all the events registered in a Safari popup so we can remove