From fbd7ff2b5d417fe99986e39e3040e3693e9b54c3 Mon Sep 17 00:00:00 2001 From: Cesar Gonzalez Date: Thu, 21 Mar 2024 12:27:12 -0500 Subject: [PATCH] [PM-5189] Implementing fixes for how positioning of the overlay element functions --- .../autofill/background/overlay.background.ts | 28 +++++++++---------- .../overlay/content/inline-menu-elements.ts | 2 +- .../autofill-overlay-content.service.ts | 4 +-- apps/browser/src/autofill/utils/index.ts | 2 +- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/apps/browser/src/autofill/background/overlay.background.ts b/apps/browser/src/autofill/background/overlay.background.ts index afa61805764..a543b6d3ceb 100644 --- a/apps/browser/src/autofill/background/overlay.background.ts +++ b/apps/browser/src/autofill/background/overlay.background.ts @@ -56,8 +56,8 @@ class OverlayBackground implements OverlayBackgroundInterface { private overlayButtonPort: chrome.runtime.Port; private overlayListPort: chrome.runtime.Port; private focusedFieldData: FocusedFieldData; - private isFieldCurrentlyFocused: boolean; - private isCurrentlyFilling: boolean; + private isFieldCurrentlyFocused: boolean = false; + private isCurrentlyFilling: boolean = false; private overlayPageTranslations: Record; private iconsServerUrl: string; private readonly extensionMessageHandlers: OverlayBackgroundExtensionMessageHandlers = { @@ -433,7 +433,7 @@ class OverlayBackground implements OverlayBackgroundInterface { { overlayElement }: { overlayElement?: string }, sender: chrome.runtime.MessageSender, ) { - if (!overlayElement) { + if (!overlayElement || sender.tab.id !== this.focusedFieldData.tabId) { return; } @@ -443,10 +443,10 @@ class OverlayBackground implements OverlayBackgroundInterface { { frameId: 0 }, ); - const subFrameOffsetsForTab = this.subFrameOffsetsForTab[sender.tab.id]; + const subFrameOffsetsForTab = this.subFrameOffsetsForTab[this.focusedFieldData.tabId]; let subFrameOffsets: SubFrameOffsetData; if (subFrameOffsetsForTab) { - subFrameOffsets = subFrameOffsetsForTab.get(sender.frameId); + subFrameOffsets = subFrameOffsetsForTab.get(this.focusedFieldData.frameId); } if (overlayElement === AutofillOverlayElement.Button) { @@ -814,7 +814,7 @@ class OverlayBackground implements OverlayBackgroundInterface { } const messageResponse = handler({ message, sender }); - if (!messageResponse) { + if (typeof messageResponse === "undefined") { return; } @@ -852,14 +852,14 @@ class OverlayBackground implements OverlayBackgroundInterface { translations: this.getTranslations(), ciphers: isOverlayListPort ? await this.getOverlayCipherData() : null, }); - // void this.updateOverlayPosition( - // { - // overlayElement: isOverlayListPort - // ? AutofillOverlayElement.List - // : AutofillOverlayElement.Button, - // }, - // port.sender, - // ); + void this.updateOverlayPosition( + { + overlayElement: isOverlayListPort + ? AutofillOverlayElement.List + : AutofillOverlayElement.Button, + }, + port.sender, + ); }; /** 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 1f42b3273ce..f88e4c6b313 100644 --- a/apps/browser/src/autofill/overlay/content/inline-menu-elements.ts +++ b/apps/browser/src/autofill/overlay/content/inline-menu-elements.ts @@ -236,7 +236,7 @@ export class InlineMenuElements implements InlineMenuElementsInterface { private updateCustomElementDefaultStyles(element: HTMLElement) { this.unobserveCustomElements(); - setElementStyles(element, this.customElementDefaultStyles, true); + this.setElementStyles(element, this.customElementDefaultStyles, true); this.observeCustomElements(); } 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 36760989c5f..02594d63069 100644 --- a/apps/browser/src/autofill/services/autofill-overlay-content.service.ts +++ b/apps/browser/src/autofill/services/autofill-overlay-content.service.ts @@ -542,9 +542,7 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte } if (!formElementHasValue || (!this.isOverlayCiphersPopulated && this.isUserAuthed())) { - // 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("openAutofillOverlay"); + void this.sendExtensionMessage("openAutofillOverlay"); return; } diff --git a/apps/browser/src/autofill/utils/index.ts b/apps/browser/src/autofill/utils/index.ts index 2644425d706..2069ba40e76 100644 --- a/apps/browser/src/autofill/utils/index.ts +++ b/apps/browser/src/autofill/utils/index.ts @@ -73,7 +73,7 @@ async function sendExtensionMessage( return new Promise((resolve) => { chrome.runtime.sendMessage(Object.assign({ command }, options), (response) => { if (chrome.runtime.lastError) { - return; + // Do nothing } resolve(response);