MDN self-hosted library · e01.org
Passkeys / notebook

Passkeys

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
try {
  const publicKeyCredential = await navigator.credentials.create({
    publicKey: options,
    mediation: "conditional",
  });
  // handle new passkey creation
  // let the user know that they have a passkey now
} catch (e) {
  // passkey was not created
}
html
<input type="text" name="username" autocomplete="username webauthn" autofocus />
js
const assertion = await navigator.credentials.get({
  publicKey: options,
  mediation: "conditional",
});