1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 17:23:37 +00:00

[PM-5189] Fixing smaller issues with how the inline menu renders

This commit is contained in:
Cesar Gonzalez
2024-04-07 17:54:53 -05:00
parent e9c351f7f3
commit 3e13cbfb5c
4 changed files with 33 additions and 14 deletions

View File

@@ -52,6 +52,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
private overlayLoginCiphers: Map<string, CipherView> = new Map(); private overlayLoginCiphers: Map<string, CipherView> = new Map();
private pageDetailsForTab: PageDetailsForTab = {}; private pageDetailsForTab: PageDetailsForTab = {};
private subFrameOffsetsForTab: SubFrameOffsetsForTab = {}; private subFrameOffsetsForTab: SubFrameOffsetsForTab = {};
private rebuildSubFrameOffsetsTimeout: number | NodeJS.Timeout;
private userAuthStatus: AuthenticationStatus = AuthenticationStatus.LoggedOut; private userAuthStatus: AuthenticationStatus = AuthenticationStatus.LoggedOut;
private overlayButtonPort: chrome.runtime.Port; private overlayButtonPort: chrome.runtime.Port;
private overlayListPort: chrome.runtime.Port; private overlayListPort: chrome.runtime.Port;
@@ -277,6 +278,10 @@ class OverlayBackground implements OverlayBackgroundInterface {
return; return;
} }
if (this.rebuildSubFrameOffsetsTimeout) {
clearTimeout(this.rebuildSubFrameOffsetsTimeout as number);
}
const frameTabs = Array.from(subFrameOffsetsForTab.keys()); const frameTabs = Array.from(subFrameOffsetsForTab.keys());
for (const frameId of frameTabs) { for (const frameId of frameTabs) {
if (frameId === sender.frameId) { if (frameId === sender.frameId) {
@@ -287,8 +292,7 @@ class OverlayBackground implements OverlayBackgroundInterface {
await this.buildSubFrameOffsets(sender.tab, frameId, sender.url); await this.buildSubFrameOffsets(sender.tab, frameId, sender.url);
} }
// TODO: Consider a better way to facilitate this delayed update this.rebuildSubFrameOffsetsTimeout = setTimeout(() => {
setTimeout(() => {
if (this.isFieldCurrentlyFocused) { if (this.isFieldCurrentlyFocused) {
void this.updateOverlayPosition({ overlayElement: AutofillOverlayElement.List }, sender); void this.updateOverlayPosition({ overlayElement: AutofillOverlayElement.List }, sender);
void this.updateOverlayPosition({ overlayElement: AutofillOverlayElement.Button }, sender); void this.updateOverlayPosition({ overlayElement: AutofillOverlayElement.Button }, sender);

View File

@@ -1,3 +1,5 @@
import { EVENTS } from "@bitwarden/common/autofill/constants";
import AutofillPageDetails from "../models/autofill-page-details"; import AutofillPageDetails from "../models/autofill-page-details";
import { InlineMenuElements } from "../overlay/abstractions/inline-menu-elements"; import { InlineMenuElements } from "../overlay/abstractions/inline-menu-elements";
import { AutofillOverlayContentService } from "../services/abstractions/autofill-overlay-content.service"; import { AutofillOverlayContentService } from "../services/abstractions/autofill-overlay-content.service";
@@ -92,7 +94,7 @@ class AutofillInit implements AutofillInitInterface {
sendCollectDetailsMessage(); sendCollectDetailsMessage();
} }
window.addEventListener("load", sendCollectDetailsMessage); globalThis.addEventListener(EVENTS.LOAD, sendCollectDetailsMessage);
} }
/** /**

View File

@@ -83,6 +83,10 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
this.formFieldElements.add(formFieldElement); this.formFieldElements.add(formFieldElement);
if (!this.mostRecentlyFocusedField) {
await this.updateMostRecentlyFocusedField(formFieldElement);
}
if (!this.autofillOverlayVisibility) { if (!this.autofillOverlayVisibility) {
await this.getAutofillOverlayVisibility(); await this.getAutofillOverlayVisibility();
} }
@@ -91,11 +95,6 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
if (this.getRootNodeActiveElement(formFieldElement) === formFieldElement) { if (this.getRootNodeActiveElement(formFieldElement) === formFieldElement) {
await this.triggerFormFieldFocusedAction(formFieldElement); await this.triggerFormFieldFocusedAction(formFieldElement);
return;
}
if (!this.mostRecentlyFocusedField) {
await this.updateMostRecentlyFocusedField(formFieldElement);
} }
} }
@@ -765,7 +764,15 @@ class AutofillOverlayContentService implements AutofillOverlayContentServiceInte
await this.updateMostRecentlyFocusedField(this.mostRecentlyFocusedField); await this.updateMostRecentlyFocusedField(this.mostRecentlyFocusedField);
this.updateOverlayElementsPosition(); this.updateOverlayElementsPosition();
setTimeout(() => this.toggleOverlayHidden(false), 50); setTimeout(() => {
this.toggleOverlayHidden(false);
if ((this.mostRecentlyFocusedField as HTMLInputElement).value) {
void this.sendExtensionMessage("closeAutofillOverlay", {
overlayElement: AutofillOverlayElement.List,
forceCloseOverlay: true,
});
}
}, 50);
this.clearUserInteractionEventTimeout(); this.clearUserInteractionEventTimeout();
if ( if (

View File

@@ -201,11 +201,17 @@ class CollectAutofillContentService implements CollectAutofillContentServiceInte
* @private * @private
*/ */
private updateCachedAutofillFieldVisibility() { private updateCachedAutofillFieldVisibility() {
this.autofillFieldElements.forEach( this.autofillFieldElements.forEach(async (autofillField, element) => {
async (autofillField, element) => const currentViewableState = autofillField.viewable;
(autofillField.viewable = autofillField.viewable = await this.domElementVisibilityService.isFormFieldViewable(element);
await this.domElementVisibilityService.isFormFieldViewable(element)),
); if (!currentViewableState && autofillField.viewable) {
await this.autofillOverlayContentService?.setupAutofillOverlayListenerOnField(
element,
autofillField,
);
}
});
} }
/** /**