diff --git a/apps/browser-extension/src/entrypoints/content.ts b/apps/browser-extension/src/entrypoints/content.ts index 14deba41e..62a4ecfb1 100644 --- a/apps/browser-extension/src/entrypoints/content.ts +++ b/apps/browser-extension/src/entrypoints/content.ts @@ -96,7 +96,7 @@ export default defineContentScript({ const target = document.getElementById(elementIdentifier) ?? document.getElementsByName(elementIdentifier)[0]; - showPopupForElement(target); + await showPopupForElement(target, true); return { success: true }; }); @@ -104,7 +104,7 @@ export default defineContentScript({ /** * Show popup for element. */ - function showPopupForElement(element: Element) : void { + async function showPopupForElement(element: Element, forceShow: boolean = false) : Promise { const { isValid, inputElement } = validateInputField(element); if (!isValid || !inputElement) { @@ -116,9 +116,16 @@ export default defineContentScript({ return; } - // This is an explicit call by the user to open the popup, so we don't check if it's enabled. - injectIcon(inputElement, container); - openAutofillPopup(inputElement, container); + /** + * By default we check if the popup is not disabled (for current site) + * but if forceShow is true, we show the popup regardless. + */ + const canShowPopup = forceShow || (await isAutoShowPopupEnabled()); + + if (canShowPopup) { + injectIcon(inputElement, container); + openAutofillPopup(inputElement, container); + } } }, }); diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts index 4afdae779..9eb5bea18 100644 --- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts +++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts @@ -368,7 +368,11 @@ export function createAutofillPopup(input: HTMLInputElement, credentials: Creden * Handle clicks on context menu items * @param e - The click event */ - const handleContextMenuClick = (e: MouseEvent): void => { + const handleContextMenuClick = (e: Event): void => { + e.preventDefault(); + e.stopPropagation(); + e.stopImmediatePropagation(); + const target = e.target as HTMLElement; const menuItem = target.closest('.av-context-menu-item') as HTMLElement; if (!menuItem) { @@ -391,7 +395,7 @@ export function createAutofillPopup(input: HTMLInputElement, credentials: Creden }; // Add click listener to handle menu item clicks - contextMenu.addEventListener('click', handleContextMenuClick); + addReliableClickHandler(contextMenu, handleContextMenuClick); }; // Add click handlers @@ -446,7 +450,7 @@ export function createVaultLockedPopup(input: HTMLInputElement, rootContainer: H container.className = 'av-vault-locked-container'; // Make the entire container clickable - container.addEventListener('click', handleUnlockClick); + addReliableClickHandler(container, handleUnlockClick); container.style.cursor = 'pointer'; // Add message @@ -488,7 +492,7 @@ export function createVaultLockedPopup(input: HTMLInputElement, rootContainer: H closeButton.style.transform = 'translateY(-50%)'; // Handle close button click - closeButton.addEventListener('click', async (e) => { + addReliableClickHandler(closeButton, async (e) => { e.stopPropagation(); // Prevent opening the unlock popup await dismissVaultLockedPopup(); removeExistingPopup(rootContainer);