Actions
Feature #3834
openAdd lazy-init CdpWebAuthnManager so WebAuthn tools always register
Start date:
07/05/2026
Due date:
% Done:
100%
Estimated time:
Description
Problem¶
WebAuthn agent tools (identity_vault_webauthn_enable, identity_vault_webauthn_disable) were gated behind `if (cdpManager)` in tools.ts. Since `cdpManager` was declared null at plugin load time and never assigned, these tools never registered. The agent could not enable or disable the virtual authenticator.
Same issue in rpc-handlers.ts: the RPC endpoints for webauthn.enable, webauthn.disable, and webauthn.loadCredentials all null-checked `cdpManager` and returned NOT_INITIALIZED.
Solution¶
- Created a `getCdpManager()` async factory in index.ts that lazily connects to the browser's CDP WebSocket and creates a CdpWebAuthnManager on first use
- Changed tools.ts and rpc-handlers.ts signatures from `cdpManager: CdpWebAuthnManager | null` to `getCdpManager: () => Promise<CdpWebAuthnManager>`
- Removed the `if (cdpManager)` gate in tools.ts — WebAuthn tools now always register
- Execute functions call `await getCdpManager()` which connects on first invocation and caches for reuse
- Added CDP connection cleanup in gateway_stop handler
Files changed¶
- `src/index.ts` — lazy-init factory, CdpConnection lifecycle
- `src/tools.ts` — unconditional tool registration, lazy-init in execute
- `src/rpc-handlers.ts` — lazy-init in RPC handlers
Testing¶
Type-checks clean. All unit tests pass (pre-existing failures unrelated). Manual integration test needed: verify tools appear and connect to browser on first use.
Actions