1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

[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

View File

@ -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<void>((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);
}
}