Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Tweak browser extension autofill popup placement and passkey cancel resolve (#2413)
Leendert de Borstfe24f84173bb
diff --git a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts b/apps/browser-extension/src/entrypoints/contentScript/Popup.tsindex e0c5cd423..b547fcd7b 100644--- a/apps/browser-extension/src/entrypoints/contentScript/Popup.ts+++ b/apps/browser-extension/src/entrypoints/contentScript/Popup.ts@@ -121,6 +121,14 @@ function isClickInsidePopupUi(event: MouseEvent, popup: Element, input: HTMLInpureturn false;}+/**+ * Whether the input a popup would anchor to has left the page or is hidden. Its rect is then all zeros,+ * which would place the popup in the top-left corner (e.g. a SPA unmounting a form mid-navigation).+ */+function isAnchorGone(input: HTMLInputElement): boolean {+ return !input.isConnected || input.getClientRects().length === 0;+}+/*** Open (or refresh) the autofill popup including check if vault is locked.* @param input - The input element that triggered the popup@@ -128,6 +136,10 @@ function isClickInsidePopupUi(event: MouseEvent, popup: Element, input: HTMLInpu* @param forceShow - If true, always show the popup even if dismissed (for manual icon clicks)*/export function openAutofillPopup(input: HTMLInputElement, container: HTMLElement, forceShow: boolean = false) : void {+ if (isAnchorGone(input)) {+ return;+ }+createLoadingPopup(input, '', container);/**@@ -187,6 +199,10 @@ export function openAutofillPopup(input: HTMLInputElement, container: HTMLElemen* @param forceShow - If true, always show the popup even if dismissed (for manual icon clicks)*/export function openTotpPopup(input: HTMLInputElement, container: HTMLElement, forceShow: boolean = false) : void {+ if (isAnchorGone(input)) {+ return;+ }+createLoadingPopup(input, '', container);/**@@ -245,6 +261,11 @@ async function createTotpPopup(input: HTMLInputElement, items: Item[] | undefineconst hidePermanentlyText = await t('content.hidePermanently');const noTotpItemsText = await t('content.noTotpItemsFound');+ if (isAnchorGone(input)) {+ removeExistingPopup(rootContainer);+ return;+ }+const popup = createBasePopup(input, rootContainer);// Create credential list container with ID@@ -826,6 +847,11 @@ export async function createAutofillPopup(input: HTMLInputElement, items: Item[]const hidePermanentlyText = await t('content.hidePermanently');const noMatchesText = await t('content.noMatchesFound');+ if (isAnchorGone(input)) {+ removeExistingPopup(rootContainer);+ return;+ }+const popup = createBasePopup(input, rootContainer);/*@@ -1107,6 +1133,11 @@ export async function createVaultLockedPopup(input: HTMLInputElement, rootContairemoveExistingPopup(rootContainer);}+ if (isAnchorGone(input)) {+ removeExistingPopup(rootContainer);+ return;+ }+const popup = createBasePopup(input, rootContainer);popup.classList.add('av-vault-locked');@@ -1588,6 +1619,11 @@ export async function createUpgradeRequiredPopup(input: HTMLInputElement, rootCoremoveExistingPopup(rootContainer);}+ if (isAnchorGone(input)) {+ removeExistingPopup(rootContainer);+ return;+ }+const popup = createBasePopup(input, rootContainer);popup.classList.add('av-upgrade-required');diff --git a/apps/browser-extension/src/entrypoints/webauthn.ts b/apps/browser-extension/src/entrypoints/webauthn.tsindex e00645925..22e15fe43 100644--- a/apps/browser-extension/src/entrypoints/webauthn.ts+++ b/apps/browser-extension/src/entrypoints/webauthn.ts@@ -318,8 +318,8 @@ export default defineUnlistedScript(() => {reject(error);}} else {- // Cancelled- resolve(null);+ // Cancelled: reject like the browser does, a null result reads as "no credential support" to most sites.+ reject(new DOMException('The operation either timed out or was not allowed.', 'NotAllowedError'));}}@@ -535,8 +535,8 @@ export default defineUnlistedScript(() => {resolve(credential);} else {- // Cancelled- resolve(null);+ // Cancelled: reject like the browser does, a null result reads as "no credential support" to most sites.+ reject(new DOMException('The operation either timed out or was not allowed.', 'NotAllowedError'));}}diff --git a/apps/web/src/utils/WebAuthnService.ts b/apps/web/src/utils/WebAuthnService.tsindex e316b0387..b9af7c432 100644--- a/apps/web/src/utils/WebAuthnService.ts+++ b/apps/web/src/utils/WebAuthnService.ts@@ -64,6 +64,10 @@ async function getCredentialDerivedKey(credentialId: string, salt: string): Promextensions: { prf: { eval: { first: base64ToBytes(salt) } } } as AuthenticationExtensionsClientInputs,},});+ if (!credential) {+ // Some passkey providers resolve null instead of rejecting when the user cancels.+ throw new DOMException('The operation either timed out or was not allowed.', 'NotAllowedError');+ }if (!hasPrf(credential)) {throw new WebAuthnNotSupportedError();}