[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
This commit is contained in:
Andreas Coroiu 2023-10-26 18:41:37 +02:00 committed by GitHub
parent 782f592c98
commit 8d2a1a89b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -149,14 +149,14 @@ navigator.credentials.get = async (
* @returns Promise that resolves when window is focused, or rejects if timeout is reached. * @returns Promise that resolves when window is focused, or rejects if timeout is reached.
*/ */
async function waitForFocus(timeout: number = 5 * 60 * 1000) { async function waitForFocus(timeout: number = 5 * 60 * 1000) {
if (document.hasFocus()) { if (window.top.document.hasFocus()) {
return; return;
} }
let focusListener; let focusListener;
const focusPromise = new Promise<void>((resolve) => { const focusPromise = new Promise<void>((resolve) => {
focusListener = () => resolve(); focusListener = () => resolve();
window.addEventListener("focus", focusListener, { once: true }); window.top.addEventListener("focus", focusListener, { once: true });
}); });
let timeoutId; let timeoutId;
@ -173,7 +173,7 @@ async function waitForFocus(timeout: number = 5 * 60 * 1000) {
try { try {
await Promise.race([focusPromise, timeoutPromise]); await Promise.race([focusPromise, timeoutPromise]);
} finally { } finally {
window.removeEventListener("focus", focusListener); window.top.removeEventListener("focus", focusListener);
window.clearTimeout(timeoutId); window.clearTimeout(timeoutId);
} }
} }