1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-10 19:38:11 +01:00

[PM-8518] Autofill scripts do not inject into sub-frames on install

This commit is contained in:
Cesar Gonzalez 2024-05-31 09:56:46 -05:00
parent 4798cd0a95
commit 814bf9de28
No known key found for this signature in database
GPG Key ID: 3381A5457F8CCECF
5 changed files with 36 additions and 6 deletions

View File

@ -124,6 +124,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, "getAllFrameDetails")
.mockResolvedValue([mock<chrome.webNavigation.GetAllFrameResultDetails>({ frameId: 0 })]);
jest
.spyOn(autofillService, "getOverlayVisibility")
.mockResolvedValue(AutofillOverlayVisibility.OnFieldFocus);
@ -134,6 +137,7 @@ describe("AutofillService", () => {
jest.spyOn(autofillService, "injectAutofillScripts");
await autofillService.loadAutofillScriptsOnInstall();
await flushPromises();
expect(BrowserApi.tabsQuery).toHaveBeenCalledWith({});
expect(autofillService.injectAutofillScripts).toHaveBeenCalledWith(tab1, 0, false);

View File

@ -2094,7 +2094,8 @@ export default class AutofillService implements AutofillServiceInterface {
for (let index = 0; index < tabs.length; index++) {
const tab = tabs[index];
if (tab.url?.startsWith("http")) {
void this.injectAutofillScripts(tab, 0, false);
const frames = await BrowserApi.getAllFrameDetails(tab.id);
frames.forEach((frame) => this.injectAutofillScripts(tab, frame.frameId, false));
}
}
}

View File

@ -62,7 +62,8 @@
"scripting",
"offscreen",
"webRequest",
"webRequestAuthProvider"
"webRequestAuthProvider",
"webNavigation"
],
"optional_permissions": ["nativeMessaging", "privacy"],
"host_permissions": ["https://*/*", "http://*/*"],

View File

@ -180,17 +180,17 @@ export class BrowserApi {
tab: chrome.tabs.Tab,
obj: T,
options: chrome.tabs.MessageSendOptions = null,
): Promise<void> {
): Promise<any> {
if (!tab || !tab.id) {
return;
}
return new Promise<void>((resolve) => {
chrome.tabs.sendMessage(tab.id, obj, options, () => {
return new Promise<any>((resolve) => {
chrome.tabs.sendMessage(tab.id, obj, options, (response) => {
if (chrome.runtime.lastError) {
// Some error happened
}
resolve();
resolve(response);
});
});
}
@ -263,6 +263,28 @@ 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<chrome.webNavigation.GetFrameResultDetails> {
return new Promise((resolve) => chrome.webNavigation.getFrame(details, resolve));
}
/**
* 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<chrome.webNavigation.GetAllFrameResultDetails[]> {
return new Promise((resolve) => chrome.webNavigation.getAllFrames({ tabId }, 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: [

View File

@ -133,6 +133,8 @@ const permissions = {
};
const webNavigation = {
getFrame: jest.fn(),
getAllFrames: jest.fn(),
onCommitted: {
addListener: jest.fn(),
removeListener: jest.fn(),