Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Sigh

Manav Rathica949ac07796
diff --git a/web/apps/accounts/src/pages/passkeys/verify.tsx b/web/apps/accounts/src/pages/passkeys/verify.tsx
index 1693af9209..448937050f 100644
--- a/web/apps/accounts/src/pages/passkeys/verify.tsx
+++ b/web/apps/accounts/src/pages/passkeys/verify.tsx
@@ -93,10 +93,6 @@ const Page = () => {
setStatus("waitingForUser");
- // Safari throws "NotAllowedError: The document is not focused" if
- // the console is open when we call `navigator.credentials.create`.
- // Not adding any workarounds, just documenting their incompetence.
-
const credential = await signChallenge(options.publicKey);
if (!credential) {
setStatus("failed");
diff --git a/web/apps/accounts/src/services/passkey.ts b/web/apps/accounts/src/services/passkey.ts
index 351e8e4728..247d54fae8 100644
--- a/web/apps/accounts/src/services/passkey.ts
+++ b/web/apps/accounts/src/services/passkey.ts
@@ -1,7 +1,9 @@
import { isDevBuild } from "@/next/env";
+import log from "@/next/log";
import { clientPackageName } from "@/next/types/app";
import { TwoFactorAuthorizationResponse } from "@/next/types/credentials";
import { ensure } from "@/utils/ensure";
+import { wait } from "@/utils/promise";
import { nullToUndefined } from "@/utils/transform";
import {
fromB64URLSafeNoPadding,
@@ -422,7 +424,30 @@ export const beginPasskeyAuthentication = async (
*/
export const signChallenge = async (
publicKey: PublicKeyCredentialRequestOptions,
-) => navigator.credentials.get({ publicKey });
+) => {
+ const go = async () => await navigator.credentials.get({ publicKey });
+
+ try {
+ return await go();
+ } catch (e) {
+ // Safari throws "NotAllowedError: The document is not focused" for the
+ // first request sometimes (no reason, just to show their incompetence).
+ // "NotAllowedError" is also the error name that is thrown when the user
+ // explicitly cancels, so we can't even filter it out by name and also
+ // to do a message match.
+ if (
+ e instanceof Error &&
+ e.name == "NotAllowedError" &&
+ e.message == "The document is not focused."
+ ) {
+ log.warn("Working around Safari bug by retrying after failure", e);
+ await wait(2000);
+ return await go();
+ } else {
+ throw e;
+ }
+ }
+};
interface FinishPasskeyAuthenticationOptions {
passkeySessionID: string;