From 68514ace530a25407838b02fed4ff522be19003c Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Thu, 21 Mar 2024 13:44:48 -0500 Subject: [PATCH] [PM-5189] Fixing issue found with how we handle re-injecting content scripts after the extension has been reloaded --- .../autofill/background/overlay.background.ts | 12 +- .../src/autofill/content/autofill-init.ts | 1 + .../content/bootstrap-autofill-overlay.ts | 2 +- .../abstractions/inline-menu-elements.ts | 1 + .../overlay/content/inline-menu-elements.ts | 1 + .../autofill-overlay-content.service.ts | 398 +----------------- .../src/autofill/services/autofill.service.ts | 6 +- 7 files changed, 21 insertions(+), 400 deletions(-) diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index 27dadb592d9..d4673100e8e 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -623,15 +623,11 @@ class OverlayBackground implements OverlayBackgroundInterface { */ private handleOverlayButtonClicked(port: chrome.runtime.Port) { if (this.userAuthStatus !== AuthenticationStatus.Unlocked) { - // 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.unlockVault(port); + void this.unlockVault(port); return; } - // 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.openOverlay(false, true); + void this.openOverlay(false, true); } /** @@ -737,9 +733,7 @@ class OverlayBackground implements OverlayBackgroundInterface { return; } - // 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 - BrowserApi.tabSendMessageData(sender.tab, "redirectOverlayFocusOut", { direction }); + void BrowserApi.tabSendMessageData(sender.tab, "redirectOverlayFocusOut", { direction }); } /** diff --git a/apps/browser/src/autofill/content/autofill-init.ts b/apps/browser/src/autofill/content/autofill-init.ts index 8afe7c8c45e..8932cdb0a09 100644 --- a/apps/browser/src/autofill/content/autofill-init.ts +++ b/apps/browser/src/autofill/content/autofill-init.ts @@ -317,6 +317,7 @@ class AutofillInit implements AutofillInitInterface { chrome.runtime.onMessage.removeListener(this.handleExtensionMessage); this.collectAutofillContentService.destroy(); this.autofillOverlayContentService?.destroy(); + this.inlineMenuElements?.destroy(); this.clearSendCollectDetailsMessageTimeout(); } } diff --git a/apps/browser/src/autofill/content/bootstrap-autofill-overlay.ts b/apps/browser/src/autofill/content/bootstrap-autofill-overlay.ts index dd32248681c..d98103a068d 100644 --- a/apps/browser/src/autofill/content/bootstrap-autofill-overlay.ts +++ b/apps/browser/src/autofill/content/bootstrap-autofill-overlay.ts @@ -8,7 +8,7 @@ import AutofillInit from "./autofill-init"; if (!windowContext.bitwardenAutofillInit) { const autofillOverlayContentService = new AutofillOverlayContentService(); let inlineMenuElements: InlineMenuElements; - if (globalThis.parent === globalThis.top) { + if (globalThis.self === globalThis.top) { inlineMenuElements = new InlineMenuElements(); } windowContext.bitwardenAutofillInit = new AutofillInit( diff --git a/apps/browser/src/autofill/overlay/abstractions/inline-menu-elements.ts b/apps/browser/src/autofill/overlay/abstractions/inline-menu-elements.ts index c1123bbfc62..268ef2ac7b8 100644 --- a/apps/browser/src/autofill/overlay/abstractions/inline-menu-elements.ts +++ b/apps/browser/src/autofill/overlay/abstractions/inline-menu-elements.ts @@ -11,4 +11,5 @@ export type InlineMenuExtensionMessageHandlers = { export interface InlineMenuElements { extensionMessageHandlers: InlineMenuExtensionMessageHandlers; + destroy: () => void; } diff --git a/apps/browser/src/autofill/overlay/content/inline-menu-elements.ts b/apps/browser/src/autofill/overlay/content/inline-menu-elements.ts index 108e698b1b9..c0219448bde 100644 --- a/apps/browser/src/autofill/overlay/content/inline-menu-elements.ts +++ b/apps/browser/src/autofill/overlay/content/inline-menu-elements.ts @@ -422,5 +422,6 @@ export class InlineMenuElements implements InlineMenuElementsInterface { } destroy() { this.documentElementMutationObserver?.disconnect(); + this.removeInlineMenu({ forceClose: true }); } } diff --git a/apps/browser/src/autofill/services/autofill-overlay-content.service.ts b/apps/browser/src/autofill/services/autofill-overlay-content.service.ts index 9422e036e9b..8bbdf09636b 100644 --- a/apps/browser/src/autofill/services/autofill-overlay-content.service.ts +++ b/apps/browser/src/autofill/services/autofill-overlay-content.service.ts @@ -7,15 +7,8 @@ import { EVENTS, AutofillOverlayVisibility } from "@bitwarden/common/autofill/co import { FocusedFieldData } from "../background/abstractions/overlay.background"; import AutofillField from "../models/autofill-field"; -// import AutofillOverlayButtonIframe from "../overlay/iframe-content/autofill-overlay-button-iframe"; -// import AutofillOverlayListIframe from "../overlay/iframe-content/autofill-overlay-list-iframe"; import { ElementWithOpId, FillableFormFieldElement, FormFieldElement } from "../types"; -import { - elementIsFillableFormField, - // generateRandomCustomElementName, - sendExtensionMessage, - // setElementStyles, -} from "../utils"; +import { elementIsFillableFormField, sendExtensionMessage } from "../utils"; import { AutofillOverlayElement, RedirectFocusDirection } from "../utils/autofill-overlay.enum"; import { @@ -26,15 +19,9 @@ import { import { AutoFillConstants } from "./autofill-constants"; class AutofillOverlayContentService implements AutofillOverlayContentServiceInterface { - // isFieldCurrentlyFocused = false; - // isCurrentlyFilling = false; isOverlayCiphersPopulated = false; pageDetailsUpdateRequired = false; autofillOverlayVisibility: number; - // private isFirefoxBrowser = - // globalThis.navigator.userAgent.indexOf(" Firefox/") !== -1 || - // globalThis.navigator.userAgent.indexOf(" Gecko/") !== -1; - // private readonly generateRandomCustomElementName = generateRandomCustomElementName; private readonly findTabs = tabbable; private readonly sendExtensionMessage = sendExtensionMessage; private formFieldElements: Set> = new Set([]); @@ -42,29 +29,14 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte private userFilledFields: Record = {}; private authStatus: AuthenticationStatus; private focusableElements: FocusableElement[] = []; - // private isOverlayButtonVisible = false; - // private isOverlayListVisible = false; - // private overlayButtonElement: HTMLElement; - // private overlayListElement: HTMLElement; private mostRecentlyFocusedField: ElementWithOpId; private focusedFieldData: FocusedFieldData; private userInteractionEventTimeout: number | NodeJS.Timeout; - // private overlayElementsMutationObserver: MutationObserver; - // private bodyElementMutationObserver: MutationObserver; - // private documentElementMutationObserver: MutationObserver; - // private mutationObserverIterations = 0; - // private mutationObserverIterationsResetTimeout: number | NodeJS.Timeout; private autofillFieldKeywordsMap: WeakMap = new WeakMap(); private eventHandlersMemo: { [key: string]: EventListener } = {}; readonly extensionMessageHandlers: AutofillOverlayContentExtensionMessageHandlers = { blurMostRecentOverlayField: () => this.blurMostRecentOverlayField, }; - // private readonly customElementDefaultStyles: Partial = { - // all: "initial", - // position: "fixed", - // display: "block", - // zIndex: "2147483647", - // }; /** * Initializes the autofill overlay content service by setting up the mutation observers. @@ -166,59 +138,11 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte this.mostRecentlyFocusedField?.blur(); } - // /** - // * Removes the autofill overlay from the page. This will initially - // * unobserve the body element to ensure the mutation observer no - // * longer triggers. - // */ - // removeAutofillOverlay = () => { - // this.removeBodyElementObserver(); - // this.removeAutofillOverlayButton(); - // this.removeAutofillOverlayList(); - // }; - - // /** - // * Removes the overlay button from the DOM if it is currently present. Will - // * also remove the overlay reposition event listeners. - // */ - // removeAutofillOverlayButton() { - // if (!this.overlayButtonElement) { - // return; - // } - // - // this.overlayButtonElement.remove(); - // this.isOverlayButtonVisible = false; - // // 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.sendExtensionMessage("autofillOverlayElementClosed", { - // overlayElement: AutofillOverlayElement.Button, - // }); - // this.removeOverlayRepositionEventListeners(); - // } - // - // /** - // * Removes the overlay list from the DOM if it is currently present. - // */ - // removeAutofillOverlayList() { - // if (!this.overlayListElement) { - // return; - // } - // - // this.overlayListElement.remove(); - // this.isOverlayListVisible = false; - // // 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.sendExtensionMessage("autofillOverlayElementClosed", { - // overlayElement: AutofillOverlayElement.List, - // }); - // } - /** * Formats any found user filled fields for a login cipher and sends a message * to the background script to add a new cipher. */ async addNewVaultItem() { - // if (!this.isOverlayListVisible) { if ((await this.sendExtensionMessage("checkIsInlineMenuListVisible")) !== true) { return; } @@ -241,7 +165,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte * @param direction - The direction to redirect the focus. */ async redirectOverlayFocusOut(direction: string) { - // if (!this.isOverlayListVisible || !this.mostRecentlyFocusedField) { if ( !this.mostRecentlyFocusedField || (await this.sendExtensionMessage("checkIsInlineMenuListVisible")) !== true @@ -251,7 +174,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte if (direction === RedirectFocusDirection.Current) { this.focusMostRecentOverlayField(); - // setTimeout(this.removeAutofillOverlay, 100); setTimeout(() => void this.sendExtensionMessage("closeAutofillOverlay"), 100); return; } @@ -345,7 +267,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte * is currently focused. */ private handleFormFieldBlurEvent = () => { - // this.isFieldCurrentlyFocused = false; void this.sendExtensionMessage("updateIsFieldCurrentlyFocused", { isFieldCurrentlyFocused: false, }); @@ -363,14 +284,12 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte private handleFormFieldKeyupEvent = async (event: KeyboardEvent) => { const eventCode = event.code; if (eventCode === "Escape") { - // this.removeAutofillOverlay(); void this.sendExtensionMessage("closeAutofillOverlay", { forceCloseOverlay: true, }); return; } - // if (eventCode === "Enter" && !this.isCurrentlyFilling) { if ( eventCode === "Enter" && !(await this.sendExtensionMessage("checkIsFieldCurrentlyFilling")) === true @@ -393,7 +312,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte * that the overlay list is focused when the user presses the down arrow key. */ private async focusOverlayList() { - // if (!this.isOverlayListVisible && this.mostRecentlyFocusedField) { if ( this.mostRecentlyFocusedField && (await this.sendExtensionMessage("checkIsInlineMenuListVisible")) !== true @@ -404,9 +322,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte return; } - // 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.sendExtensionMessage("focusAutofillOverlayList"); + void this.sendExtensionMessage("focusAutofillOverlayList"); } /** @@ -436,7 +352,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte this.storeModifiedFormElement(formFieldElement); if (formFieldElement.value && (this.isOverlayCiphersPopulated || !this.isUserAuthed())) { - // this.removeAutofillOverlayList(); void this.sendExtensionMessage("closeAutofillOverlay", { overlayElement: AutofillOverlayElement.List, forceCloseOverlay: true, @@ -487,7 +402,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte * @param formFieldElement - The form field element that triggered the click event. */ private async triggerFormFieldClickedAction(formFieldElement: ElementWithOpId) { - // if (this.isOverlayButtonVisible || this.isOverlayListVisible) { if ( (await this.sendExtensionMessage("checkIsInlineMenuButtonVisible")) === true || (await this.sendExtensionMessage("checkIsInlineMenuListVisible")) === true @@ -518,12 +432,10 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte * @param formFieldElement - The form field element that triggered the focus event. */ private async triggerFormFieldFocusedAction(formFieldElement: ElementWithOpId) { - // if (this.isCurrentlyFilling) { if ((await this.sendExtensionMessage("checkIsFieldCurrentlyFilling")) === true) { return; } - // this.isFieldCurrentlyFocused = true; void this.sendExtensionMessage("updateIsFieldCurrentlyFocused", { isFieldCurrentlyFocused: true, }); @@ -536,7 +448,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte this.autofillOverlayVisibility === AutofillOverlayVisibility.OnButtonClick || (formElementHasValue && initiallyFocusedField !== this.mostRecentlyFocusedField) ) { - // this.removeAutofillOverlayList(); void this.sendExtensionMessage("closeAutofillOverlay", { overlayElement: AutofillOverlayElement.List, forceCloseOverlay: true, @@ -625,22 +536,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte * Updates the position of the overlay button. */ private updateOverlayButtonPosition() { - // if (!this.overlayButtonElement) { - // this.createAutofillOverlayButton(); - // this.updateCustomElementDefaultStyles(this.overlayButtonElement); - // } - // - // if (!this.isOverlayButtonVisible) { - // this.appendOverlayElementToBody(this.overlayButtonElement); - // this.isOverlayButtonVisible = true; - // this.setOverlayRepositionEventListeners(); - // } - // // 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.sendExtensionMessage("updateAutofillOverlayPosition", { - // overlayElement: AutofillOverlayElement.Button, - // }); - void this.sendExtensionMessage("updateAutofillOverlayPosition", { overlayElement: AutofillOverlayElement.Button, }); @@ -650,39 +545,11 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte * Updates the position of the overlay list. */ private updateOverlayListPosition() { - // if (!this.overlayListElement) { - // this.createAutofillOverlayList(); - // this.updateCustomElementDefaultStyles(this.overlayListElement); - // } - // - // if (!this.isOverlayListVisible) { - // this.appendOverlayElementToBody(this.overlayListElement); - // this.isOverlayListVisible = true; - // } - // - // // 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.sendExtensionMessage("updateAutofillOverlayPosition", { - // overlayElement: AutofillOverlayElement.List, - // }); - void this.sendExtensionMessage("updateAutofillOverlayPosition", { overlayElement: AutofillOverlayElement.List, }); } - // /** - // * Appends the overlay element to the body element. This method will also - // * observe the body element to ensure that the overlay element is not - // * interfered with by any DOM changes. - // * - // * @param element - The overlay element to append to the body element. - // */ - // private appendOverlayElementToBody(element: HTMLElement) { - // this.observeBodyElement(); - // globalThis.document.body.appendChild(element); - // } - /** * Sends a message that facilitates hiding the overlay elements. * @@ -796,78 +663,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte return !isLoginCipherField; } - // /** - // * Creates the autofill overlay button element. Will not attempt - // * to create the element if it already exists in the DOM. - // */ - // private createAutofillOverlayButton() { - // if (this.overlayButtonElement) { - // return; - // } - // - // if (this.isFirefoxBrowser) { - // this.overlayButtonElement = globalThis.document.createElement("div"); - // new AutofillOverlayButtonIframe(this.overlayButtonElement); - // - // return; - // } - // - // const customElementName = this.generateRandomCustomElementName(); - // globalThis.customElements?.define( - // customElementName, - // class extends HTMLElement { - // constructor() { - // super(); - // new AutofillOverlayButtonIframe(this); - // } - // }, - // ); - // this.overlayButtonElement = globalThis.document.createElement(customElementName); - // } - // - // /** - // * Creates the autofill overlay list element. Will not attempt - // * to create the element if it already exists in the DOM. - // */ - // private createAutofillOverlayList() { - // if (this.overlayListElement) { - // return; - // } - // - // if (this.isFirefoxBrowser) { - // this.overlayListElement = globalThis.document.createElement("div"); - // new AutofillOverlayListIframe(this.overlayListElement); - // - // return; - // } - // - // const customElementName = this.generateRandomCustomElementName(); - // globalThis.customElements?.define( - // customElementName, - // class extends HTMLElement { - // constructor() { - // super(); - // new AutofillOverlayListIframe(this); - // } - // }, - // ); - // this.overlayListElement = globalThis.document.createElement(customElementName); - // } - - // /** - // * Updates the default styles for the custom element. This method will - // * remove any styles that are added to the custom element by other methods. - // * - // * @param element - The custom element to update the default styles for. - // */ - // private updateCustomElementDefaultStyles(element: HTMLElement) { - // this.unobserveCustomElements(); - // - // setElementStyles(element, this.customElementDefaultStyles, true); - // - // this.observeCustomElements(); - // } - /** * Queries the background script for the autofill overlay visibility setting. * If the setting is not found, a default value of OnFieldFocus will be used @@ -905,7 +700,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte * repositioning of the overlay. */ private handleOverlayRepositionEvent = async () => { - // if (!this.isOverlayButtonVisible && !this.isOverlayListVisible) { if ( (await this.sendExtensionMessage("checkIsInlineMenuButtonVisible")) !== true && (await this.sendExtensionMessage("checkIsInlineMenuListVisible")) !== true @@ -928,8 +722,9 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte private triggerOverlayRepositionUpdates = async () => { if (!this.recentlyFocusedFieldIsCurrentlyFocused()) { this.toggleOverlayHidden(false); - // this.removeAutofillOverlay(); - void this.sendExtensionMessage("closeAutofillOverlay"); + void this.sendExtensionMessage("closeAutofillOverlay", { + forceCloseOverlay: true, + }); return; } @@ -945,8 +740,9 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte return; } - // this.removeAutofillOverlay(); - void this.sendExtensionMessage("closeAutofillOverlay"); + void this.sendExtensionMessage("closeAutofillOverlay", { + forceCloseOverlay: true, + }); }; /** @@ -968,7 +764,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte globalThis.document.addEventListener(EVENTS.VISIBILITYCHANGE, this.handleVisibilityChangeEvent); globalThis.addEventListener(EVENTS.FOCUSOUT, this.handleFormFieldBlurEvent); this.setOverlayRepositionEventListeners(); - // this.setupMutationObserver(); }; /** @@ -981,180 +776,11 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte } this.mostRecentlyFocusedField = null; - // this.removeAutofillOverlay(); - void this.sendExtensionMessage("closeAutofillOverlay"); + void this.sendExtensionMessage("closeAutofillOverlay", { + forceCloseOverlay: true, + }); }; - // /** - // * Sets up mutation observers for the overlay elements, the body element, and the - // * document element. The mutation observers are used to remove any styles that are - // * added to the overlay elements by the website. They are also used to ensure that - // * the overlay elements are always present at the bottom of the body element. - // */ - // private setupMutationObserver = () => { - // this.overlayElementsMutationObserver = new MutationObserver( - // this.handleOverlayElementMutationObserverUpdate, - // ); - // - // this.bodyElementMutationObserver = new MutationObserver( - // this.handleBodyElementMutationObserverUpdate, - // ); - // }; - - // /** - // * Sets up mutation observers to verify that the overlay - // * elements are not modified by the website. - // */ - // private observeCustomElements() { - // if (this.overlayButtonElement) { - // this.overlayElementsMutationObserver?.observe(this.overlayButtonElement, { - // attributes: true, - // }); - // } - // - // if (this.overlayListElement) { - // this.overlayElementsMutationObserver?.observe(this.overlayListElement, { attributes: true }); - // } - // } - - // /** - // * Disconnects the mutation observers that are used to verify that the overlay - // * elements are not modified by the website. - // */ - // private unobserveCustomElements() { - // this.overlayElementsMutationObserver?.disconnect(); - // } - - // /** - // * Sets up a mutation observer for the body element. The mutation observer is used - // * to ensure that the overlay elements are always present at the bottom of the body - // * element. - // */ - // private observeBodyElement() { - // this.bodyElementMutationObserver?.observe(globalThis.document.body, { childList: true }); - // } - - // /** - // * Disconnects the mutation observer for the body element. - // */ - // private removeBodyElementObserver() { - // this.bodyElementMutationObserver?.disconnect(); - // } - - // /** - // * Handles the mutation observer update for the overlay elements. This method will - // * remove any attributes or styles that might be added to the overlay elements by - // * a separate process within the website where this script is injected. - // * - // * @param mutationRecord - The mutation record that triggered the update. - // */ - // private handleOverlayElementMutationObserverUpdate = (mutationRecord: MutationRecord[]) => { - // if (this.isTriggeringExcessiveMutationObserverIterations()) { - // return; - // } - // - // for (let recordIndex = 0; recordIndex < mutationRecord.length; recordIndex++) { - // const record = mutationRecord[recordIndex]; - // if (record.type !== "attributes") { - // continue; - // } - // - // const element = record.target as HTMLElement; - // if (record.attributeName !== "style") { - // this.removeModifiedElementAttributes(element); - // - // continue; - // } - // - // element.removeAttribute("style"); - // this.updateCustomElementDefaultStyles(element); - // } - // }; - - // /** - // * Removes all elements from a passed overlay - // * element except for the style attribute. - // * - // * @param element - The element to remove the attributes from. - // */ - // private removeModifiedElementAttributes(element: HTMLElement) { - // const attributes = Array.from(element.attributes); - // for (let attributeIndex = 0; attributeIndex < attributes.length; attributeIndex++) { - // const attribute = attributes[attributeIndex]; - // if (attribute.name === "style") { - // continue; - // } - // - // element.removeAttribute(attribute.name); - // } - // } - - // /** - // * Handles the mutation observer update for the body element. This method will - // * ensure that the overlay elements are always present at the bottom of the body - // * element. - // */ - // private handleBodyElementMutationObserverUpdate = () => { - // if ( - // (!this.overlayButtonElement && !this.overlayListElement) || - // this.isTriggeringExcessiveMutationObserverIterations() - // ) { - // return; - // } - // - // const lastChild = globalThis.document.body.lastElementChild; - // const secondToLastChild = lastChild?.previousElementSibling; - // const lastChildIsOverlayList = lastChild === this.overlayListElement; - // const lastChildIsOverlayButton = lastChild === this.overlayButtonElement; - // const secondToLastChildIsOverlayButton = secondToLastChild === this.overlayButtonElement; - // - // if ( - // (lastChildIsOverlayList && secondToLastChildIsOverlayButton) || - // (lastChildIsOverlayButton && !this.isOverlayListVisible) - // ) { - // return; - // } - // - // if ( - // (lastChildIsOverlayList && !secondToLastChildIsOverlayButton) || - // (lastChildIsOverlayButton && this.isOverlayListVisible) - // ) { - // globalThis.document.body.insertBefore(this.overlayButtonElement, this.overlayListElement); - // return; - // } - // - // globalThis.document.body.insertBefore(lastChild, this.overlayButtonElement); - // }; - - // /** - // * Identifies if the mutation observer is triggering excessive iterations. - // * Will trigger a blur of the most recently focused field and remove the - // * autofill overlay if any set mutation observer is triggering - // * excessive iterations. - // */ - // private isTriggeringExcessiveMutationObserverIterations() { - // if (this.mutationObserverIterationsResetTimeout) { - // clearTimeout(this.mutationObserverIterationsResetTimeout); - // } - // - // this.mutationObserverIterations++; - // this.mutationObserverIterationsResetTimeout = setTimeout( - // () => (this.mutationObserverIterations = 0), - // 2000, - // ); - // - // if (this.mutationObserverIterations > 100) { - // clearTimeout(this.mutationObserverIterationsResetTimeout); - // this.mutationObserverIterations = 0; - // this.blurMostRecentOverlayField(); - // this.removeAutofillOverlay(); - // - // return true; - // } - // - // return false; - // } - /** * Gets the root node of the passed element and returns the active element within that root node. * @@ -1174,7 +800,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte * disconnect the mutation observers and remove all event listeners. */ destroy() { - // this.documentElementMutationObserver?.disconnect(); this.clearUserInteractionEventTimeout(); this.formFieldElements.forEach((formFieldElement) => { this.removeCachedFormFieldEventListeners(formFieldElement); @@ -1187,7 +812,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte this.handleVisibilityChangeEvent, ); globalThis.removeEventListener(EVENTS.FOCUSOUT, this.handleFormFieldBlurEvent); - // this.removeAutofillOverlay(); this.removeOverlayRepositionEventListeners(); } } diff --git a/apps/browser/src/autofill/services/autofill.service.ts b/apps/browser/src/autofill/services/autofill.service.ts index e353a34ea07..9d94a0c36d0 100644 --- a/apps/browser/src/autofill/services/autofill.service.ts +++ b/apps/browser/src/autofill/services/autofill.service.ts @@ -2066,9 +2066,9 @@ export default class AutofillService implements AutofillServiceInterface { for (let index = 0; index < tabs.length; index++) { const tab = tabs[index]; if (tab.url?.startsWith("http")) { - // 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.injectAutofillScripts(tab, 0, false); + chrome.webNavigation.getAllFrames({ tabId: tab.id }, (frames) => + frames.forEach((frame) => this.injectAutofillScripts(tab, frame.frameId, false)), + ); } } }