Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add popup show debounce to prevent autofill from spamming popup (#541)
Leendert de Borst533065c7d357
diff --git a/browser-extensions/chrome/contentScript.ts b/browser-extensions/chrome/contentScript.tsindex 10a782aa9..10af194df 100644--- a/browser-extensions/chrome/contentScript.ts+++ b/browser-extensions/chrome/contentScript.ts@@ -1,6 +1,6 @@import { FormDetector } from './src/shared/formDetector/FormDetector';import { isAutoShowPopupDisabled, openAutofillPopup, removeExistingPopup } from './src/contentScript/Popup';-import { injectIcon } from './src/contentScript/Form';+import { canShowPopup, injectIcon } from './src/contentScript/Form';/*** Listen for input field focus@@ -20,7 +20,10 @@ document.addEventListener('focusin', async (e) => {injectIcon(target);const isDisabled = await isAutoShowPopupDisabled();- if (!isDisabled) {+ const canShow = canShowPopup();++ // Only show popup if it's not disabled and the popup can be shown (not blocked by debounce)+ if (!isDisabled && canShow) {openAutofillPopup(target);}}diff --git a/browser-extensions/chrome/src/contentScript/Form.ts b/browser-extensions/chrome/src/contentScript/Form.tsindex b0736da02..dd6baceca 100644--- a/browser-extensions/chrome/src/contentScript/Form.ts+++ b/browser-extensions/chrome/src/contentScript/Form.ts@@ -2,6 +2,32 @@ import { FormDetector } from "../shared/formDetector/FormDetector";import { Credential } from "../shared/types/Credential";import { openAutofillPopup } from "./Popup";+/**+ * Global timestamp to track popup debounce time.+ * This is used to not show the popup again for a specific amount of time.+ * Used after autofill events to prevent spamming the popup from automatic+ * triggered browser events which can cause "focus" events to trigger.+ */+let popupDebounceTime = 0;++/**+ * Check if popup can be shown based on debounce time.+ */+export function canShowPopup() : boolean {+ if (Date.now() < popupDebounceTime) {+ return false;+ }++ return true;+}++/**+ * Hide popup for a specific amount of time.+ */+export function hidePopupFor(ms: number) : void {+ popupDebounceTime = Date.now() + ms;+}+/*** Fill credential into current form.*@@ -9,6 +35,9 @@ import { openAutofillPopup } from "./Popup";* @param input - The input element that triggered the popup. Required when filling credentials to know which form to fill.*/export function fillCredential(credential: Credential, input: HTMLInputElement) : void {+ // Set debounce time to 800ms to prevent the popup from being shown again within 800ms because of autofill events.+ hidePopupFor(800);+const formDetector = new FormDetector(document, input);const forms = formDetector.detectForms();