playwright-client-certificate-login is a Node.js utility, currently at version 0.0.3, designed to streamline client certificate-based authentication within Playwright automation scripts. It abstracts the complexities of configuring Playwright's browser context to utilize PFX/PKCS12 files or separate PEM certificate and key files, including their associated passphrases. The library provides a `CertificateAuthSession` class that manages the entire authentication process, from launching a browser and navigating to the specified URL, to making the authenticated browser context, page, cookies, and headers accessible. Given its early version, the package is in active development with an implied irregular release cadence, primarily focusing on robust client certificate handling for scenarios such as SAP BTP and other enterprise authentication systems.
npm install playwright-client-certificate-loginVerified import paths — ran on the pinned version, not inferred.
Demonstrates authenticating to a web application using a PFX client certificate, capturing cookies, headers, and taking a screenshot of the authenticated page.
Refer to the latest README or GitHub releases for any changes when updating the package.
Consider using Playwright's `clientCertificates` option in `use` block of `playwright.config.ts` for native integration if this package's abstraction is not precisely what's needed.
Always use environment variables (e.g., `process.env.PFX_PASSPHRASE`) or a secure secret management system to inject certificate credentials at runtime.
Ensure that the `origin` specified exactly matches the server's certificate request origin. Test thoroughly in different browser environments. In some stubborn cases, manual interaction might be unavoidable or a different approach (like using an authentication proxy) might be necessary.
Ensure `origin`, `url`, and one of (`pfxPath`/`pfxBuffer`) or (`certPath`/`certBuffer` and `keyPath`/`keyBuffer`) are supplied in the options object.
Verify that the file paths are correct and absolute, and that the Node.js process has the necessary permissions to access the certificate files.
Increase the `timeout` option in the `CertificateAuthSession` constructor for pages with longer loading times, or debug network issues/authentication flow if the page genuinely isn't loading.