From 8d2a1a89b722ed2389b650b4eae570abc176997e Mon Sep 17 00:00:00 2001 From: Andreas Coroiu Date: Thu, 26 Oct 2023 18:41:37 +0200 Subject: [PATCH] [PM-4553] [Defect] Browser fallback fails on first click on bitwarden (#6706) * [PM-4553] feat: add focus listener to parent * [PM-4553] feat: user `window.top` instead --- apps/browser/src/vault/fido2/content/page-script.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/browser/src/vault/fido2/content/page-script.ts b/apps/browser/src/vault/fido2/content/page-script.ts index 986173a4a4..44a443b89e 100644 --- a/apps/browser/src/vault/fido2/content/page-script.ts +++ b/apps/browser/src/vault/fido2/content/page-script.ts @@ -149,14 +149,14 @@ navigator.credentials.get = async ( * @returns Promise that resolves when window is focused, or rejects if timeout is reached. */ async function waitForFocus(timeout: number = 5 * 60 * 1000) { - if (document.hasFocus()) { + if (window.top.document.hasFocus()) { return; } let focusListener; const focusPromise = new Promise((resolve) => { focusListener = () => resolve(); - window.addEventListener("focus", focusListener, { once: true }); + window.top.addEventListener("focus", focusListener, { once: true }); }); let timeoutId; @@ -173,7 +173,7 @@ async function waitForFocus(timeout: number = 5 * 60 * 1000) { try { await Promise.race([focusPromise, timeoutPromise]); } finally { - window.removeEventListener("focus", focusListener); + window.top.removeEventListener("focus", focusListener); window.clearTimeout(timeoutId); } }