A virtual authenticator for browser tests with PhoenixTest.Playwright.
A passkey ceremony needs an authenticator in the browser. Chrome emulates one through the WebAuthn domain of the Chrome DevTools Protocol. This module reaches it over a CDP session on the test's page. It works with Playwright's Chromium only.
Playwright's own credentials API replaces navigator.credentials with a script. In
Playwright 1.64 that script returns no extension results and does not check the relying party
id against the origin. The CDP authenticator runs behind Chrome's WebAuthn client.
The authenticator id and the CDP session are kept in the test process. Call these functions from that process.
test "a passkey signs back in", %{conn: conn} do
virtual_authenticator(conn)
# ... register through the page ...
assert length(credentials(conn)) == 1
endThe module exists only when phoenix_test_playwright is a dependency.
Summary
Functions
Returns the credentials the page's authenticator holds.
Deletes every credential the page's authenticator holds and returns conn.
Adds a virtual platform authenticator to the page and returns conn.
Functions
Returns the credentials the page's authenticator holds.
A ceremony that reached navigator.credentials.create leaves one here.
Deletes every credential the page's authenticator holds and returns conn.
The authenticator then holds no passkey, like a device that never registered one.
Adds a virtual platform authenticator to the page and returns conn.
The authenticator holds discoverable credentials, verifies the user and answers every prompt by itself. No credential is seeded, so each test registers its own passkey. A second call on the same page does nothing.