Skip to content

Commit 8919aa8

Browse files
committed
Added logging and more error handling
1 parent af0560c commit 8919aa8

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

  • packages/javascript-sdk/src/fr-webauthn

packages/javascript-sdk/src/fr-webauthn/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { CallbackType } from '../auth/enums';
1313
import type HiddenValueCallback from '../fr-auth/callbacks/hidden-value-callback';
1414
import type MetadataCallback from '../fr-auth/callbacks/metadata-callback';
1515
import type FRStep from '../fr-auth/fr-step';
16+
import { FRLogger } from '../util/logger';
1617
import { WebAuthnOutcome, WebAuthnOutcomeType, WebAuthnStepType } from './enums';
1718
import {
1819
arrayBufferToString,
@@ -30,6 +31,7 @@ import type {
3031
} from './interfaces';
3132
import type TextOutputCallback from '../fr-auth/callbacks/text-output-callback';
3233
import { parseWebAuthnAuthenticateText, parseWebAuthnRegisterText } from './script-parser';
34+
import { withTimeout } from '../util/timeout';
3335

3436
// <clientdata>::<attestation>::<publickeyCredential>::<DeviceName>
3537
type OutcomeWithName<
@@ -44,6 +46,8 @@ type OutcomeWithName<
4446
type WebAuthnMetadata = WebAuthnAuthenticationMetadata | WebAuthnRegistrationMetadata;
4547
// Script-based WebAuthn
4648
type WebAuthnTextOutput = WebAuthnTextOutputRegistration;
49+
const ONE_SECOND = 1000;
50+
4751
/**
4852
* Utility for integrating a web browser's WebAuthn API.
4953
*
@@ -123,10 +127,12 @@ abstract class FRWebAuthn {
123127
}
124128

125129
// Check if the browser supports conditional mediation
126-
if (typeof PublicKeyCredential.isConditionalMediationAvailable === 'function') {
127-
return await PublicKeyCredential.isConditionalMediationAvailable();
130+
try{
131+
return withTimeout(PublicKeyCredential.isConditionalMediationAvailable(), ONE_SECOND)
132+
} catch {
133+
throw new Error('Error determining conditional mediation support');
128134
}
129-
135+
130136
return false;
131137
}
132138

@@ -370,6 +376,7 @@ abstract class FRWebAuthn {
370376
credentialRequestOptions.mediation = 'conditional' as CredentialMediationRequirement;
371377
} else {
372378
// eslint-disable-next-line no-console
379+
FRLogger.warn('Conditional UI was requested, but is not supported by this browser.');
373380
console.warn('Conditional UI was requested, but is not supported by this browser.');
374381
}
375382
}

0 commit comments

Comments
 (0)