Credentials
Credentials is a virtual WebAuthn authenticator scoped to a BrowserContext. It lets tests register passkeys and answer navigator.credentials.create() / navigator.credentials.get() ceremonies in the page, without a real authenticator or hardware security key.
There are three common ways to use it:
Usage: seed a known credential
BrowserContext context = browser.newContext();
// A passkey your backend already provisioned for a test user.
context.credentials().create("example.com", new Credentials.CreateOptions()
.setId(knownCredentialId) // base64url
.setUserHandle(knownUserHandle) // base64url
.setPrivateKey(knownPrivateKey) // base64url PKCS#8 (DER)
.setPublicKey(knownPublicKey)); // base64url SPKI (DER)
context.credentials().install();
Page page = context.newPage();
page.navigate("https://example.com/login");
// The page's navigator.credentials.get() is answered with the seeded passkey.
Usage: capture a credential, then reuse it
// setup test: let the app register a passkey, then save it.
BrowserContext context = browser.newContext();
context.credentials().install();
Page page = context.newPage();
page.navigate("https://example.com/register");
page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName("Create a passkey")).click();
// Read back the passkey the page registered — it includes the private key.
VirtualCredential credential = context.credentials().get(
new Credentials.GetOptions().setRpId("example.com")).get(0);
Files.writeString(Paths.get("playwright/.auth/passkey.json"), new Gson().toJson(credential));
// later test: seed the captured passkey so the app starts already enrolled.
VirtualCredential credential = new Gson().fromJson(
Files.readString(Paths.get("playwright/.auth/passkey.json")), VirtualCredential.class);
BrowserContext context = browser.newContext();
context.credentials().create(credential.rpId, new Credentials.CreateOptions()
.setId(credential.id)