const credInit = {
id: "serpent1234", // "username" in a typical username/password pair
name: "Serpentina", // display name for credential
origin: "https://example.org",
password: "the last visible dog",
};
const makeCredential = document.querySelector("#make-credential");
makeCredential.addEventListener("click", async () => {
const cred = await navigator.credentials.create({
password: credInit,
});
console.log(cred.name);
// Serpentina
console.log(cred.id);
// serpent1234
console.log(cred.password);
// the last visible dog
});PasswordCredentialInit / notebook
PasswordCredentialInit
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
<form>
<div>
<label for="displayname">Enter your display name: </label>
<input
type="text"
name="displayname"
id="displayname"
autocomplete="name" />
</div>
<div>
<label for="username">Enter your username: </label>
<input type="text" name="username" id="username" autocomplete="username" />
</div>
<div>
<label for="password">Enter your password: </label>
<input
type="password"
name="password"
id="password"
autocomplete="new-password" />
</div>
</form>
<button id="make-credential">Make credential</button>
<pre id="log"></pre>