A robust TypeScript wrapper around the Web Credential Management API.
The credentialContainer class provides a clean, user-friendly API to handle browser credentials, enhancing the native browser APIs.
Install the package via npm:
npm install webcredEnsure your project is configured for TypeScript!
The credentialContainer class exposes type-safe utilities to interact with the Web Credential Management API.
All methods include built-in feature detection, so they’ll gracefully return null or false in unsupported environments instead of throwing.
-
credentialTypeRepresents the type of credentials handled by the API:password→PasswordCredentialfederated→FederatedCredentialotp→OTPCredentialpublicKey→PublicKeyCredential
-
mediationControls how the browser mediates the credential retrieval process:silent— No UI; fails if the user has not granted permission.optional— Tries to retrieve credentials without requiring user interaction.required— Always requires user interaction.conditional— Enables Conditional UI.
These methods let you check support before performing any operations:
-
isSecureContextOrLocalhost(): booleanReturnstrueif the current environment is HTTPS orlocalhost. -
isSupported(): booleanReturnstrueif the browser supports the Credential Management API. -
isPasswordCredentialSupported(): boolean -
isFederatedCredentialSupported(): boolean -
isOTPCredentialSupported(): boolean -
isPublicKeyCredentialSupported(): booleanReturntrueif the corresponding credential type is supported.
-
storePasswordCredential(data: PasswordCredentialData): Promise<PasswordCredential | null>Stores a password credential usingnavigator.credentials.store. -
getPasswordCredential(mediation?: CredentialMediationRequirement, signal?: AbortSignal): Promise<PasswordCredential | null>Retrieves a stored password credential. Default mediation is"optional".
-
storeFederatedCredential(data: FederatedCredentialData): Promise<FederatedCredential | null>Stores a federated credential (e.g., Google, Facebook, etc.). -
getFederatedCredential(options: FederatedCredentialRequestOptions, mediation?: CredentialMediationRequirement, signal?: AbortSignal): Promise<FederatedCredential | null>Retrieves a federated credential based on the given provider options.
-
storeOTPCredential(data: OTPCredentialData): Promise<OTPCredential | null>Stores a one-time password credential. -
getOTPCredential(options: OTPCredentialRequestOptions, mediation?: CredentialMediationRequirement, signal?: AbortSignal): Promise<OTPCredential | null>Retrieves an OTP credential via the browser’s Web OTP API.
-
storePublicKeyCredential(data: PublicKeyCredentialCreationOptions, signal?: AbortSignal): Promise<PublicKeyCredential | null>Registers a new credential using the WebAuthncreate()API. -
getPublicKeyCredential(options: PublicKeyCredentialRequestOptions, mediation?: CredentialMediationRequirement, signal?: AbortSignal): Promise<PublicKeyCredential | null>Retrieves a previously registered WebAuthn credential using theget()API.
The Credential Management API is available in most modern browsers, but support varies depending on the credential type.
| Credential Type | Chrome / Edge | Firefox | Safari | Notes |
|---|---|---|---|---|
| PasswordCredential | ✅ | ✅ | Safari has partial support and may not implement storage consistently | |
| FederatedCredential | ✅ | ❌ | Firefox support is experimental; Safari does not support it | |
| OTPCredential | ✅ | ❌ | ❌ | Supported through the Web OTP API |
| PublicKeyCredential | ✅ | ✅ | ✅ | WebAuthn is well supported across major browsers |
Requirements
- Must run in a secure context (HTTPS or
localhost). - Some features depend on user permissions or browser autofill settings.
- Always check support with
isSupported()andis*CredentialSupported()before calling any methods.
This library performs these checks automatically, so in unsupported environments, calls will safely return null or false without throwing.
Contributions are welcome! Whether it's fixing a typo, improving docs, or adding new features — your help makes this library better. Please follow these steps:
- Clone the repository.
- Create a feature branch (
git checkout -b feature/my-feature). - Commit changes (
git commit -m 'Add my feature'). - Push to the branch (
git push origin feature/my-feature). - Open a pull request.
MIT License. See LICENSE for details.
Report bugs or suggest features via the GitHub Issues page.