mirror of
https://github.com/keepassxreboot/keepassxc-browser.git
synced 2026-03-11 08:54:43 +00:00
Merge 7c6b3bff0a into b46c1a1199
This commit is contained in:
commit
c991f59ab2
1 changed files with 29 additions and 2 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) {
|
||||
|
|
@ -203,8 +226,10 @@
|
|||
if (!response.publicKey) {
|
||||
if (!response.fallback) {
|
||||
throwError(response?.errorCode, response?.errorMessage);
|
||||
return null;
|
||||
}
|
||||
return response.fallback ? originalCredentials.create(options) : null;
|
||||
await waitForFocus();
|
||||
return originalCredentials.create(options);
|
||||
}
|
||||
|
||||
return createPublicKeyCredential(response.publicKey);
|
||||
|
|
@ -228,8 +253,10 @@
|
|||
if (!response.publicKey) {
|
||||
if (!response.fallback) {
|
||||
throwError(response?.errorCode, response?.errorMessage);
|
||||
return null;
|
||||
}
|
||||
return response.fallback ? originalCredentials.get(options) : null;
|
||||
await waitForFocus();
|
||||
return originalCredentials.get(options);
|
||||
}
|
||||
|
||||
return createPublicKeyCredential(response.publicKey);
|
||||
|
|
|
|||
Loading…
Reference in a new issue