mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Waiting for the focus to return from KeePassXC-desktop back to the page
This commit is contained in:
parent
9e5a936e2a
commit
7c6b3bff0a
1 changed files with 25 additions and 0 deletions
|
|
@ -145,6 +145,29 @@
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const waitForFocus = function () {
|
||||
/*
|
||||
Some browsers (Firefox, Safari) reject requests to original `navigator.credentials.create/get` if the page
|
||||
is out of focus (when the user selects a passkey in KeePassXC-desktop).
|
||||
|
||||
`document.visibilityState` is not suitable: if the page is visible, but the focus is on another application
|
||||
(or DevTools), the request will be rejected.
|
||||
*/
|
||||
return new Promise((resolve) => {
|
||||
if (document.hasFocus()) {
|
||||
return resolve();
|
||||
}
|
||||
document.addEventListener(
|
||||
'focus',
|
||||
() => resolve(),
|
||||
{ capture: true, passive: true, once: true }
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
// Throws errors to a correct exceptions
|
||||
const throwError = function(errorCode, errorMessage) {
|
||||
if ((!errorCode && !errorMessage) || errorCode === PASSKEYS_REQUEST_CANCELED) {
|
||||
|
|
@ -205,6 +228,7 @@
|
|||
throwError(response?.errorCode, response?.errorMessage);
|
||||
return null;
|
||||
}
|
||||
await waitForFocus();
|
||||
return originalCredentials.create(options);
|
||||
}
|
||||
|
||||
|
|
@ -231,6 +255,7 @@
|
|||
throwError(response?.errorCode, response?.errorMessage);
|
||||
return null;
|
||||
}
|
||||
await waitForFocus();
|
||||
return originalCredentials.get(options);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue