npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

playwright-client-certificate-login

v0.0.2

Published

A playwright script to login using client certificates

Downloads

183

Readme

Playwright Client Certificate Authentication

A Node.js utility for authenticating using client certificates via Playwright.

Installation

npm install playwright-client-certificate-login

Usage

const { CertificateAuthSession } = require('playwright-client-certificate-login');

// Using PFX/PKCS12 certificate
const options = {
  origin: 'https://your-domain.com',
  url: 'https://your-domain.com/path',
  pfxPath: '/path/to/your/certificate.pfx',
  passphrase: 'your-certificate-passphrase'
};

// Or using separate cert and key files
const options = {
  origin: 'https://your-domain.com',
  url: 'https://your-domain.com/path',
  certPath: '/path/to/your/certificate.pem',
  keyPath: '/path/to/your/private-key.pem',
  passphrase: 'your-key-passphrase'
};

async function authenticate() {
  const session = new CertificateAuthSession(options);
  try {
    await session.authenticate();
    
    // Access authenticated session data
    const cookies = session.getCookies();
    const headers = session.getHeaders();
    const browser = session.getBrowser();
    const context = session.getContext();
    const page = session.getPage();
    
    console.log('Authentication successful:', cookies);
    
    // Don't forget to close the session
    await session.close();
  } catch (error) {
    console.error('Authentication failed:', error);
  }
}

API Reference

Class: CertificateAuthSession

Constructor Options

| Parameter | Type | Required | Description | |-----------|------|----------|-------------| | origin | string | Yes | The exact origin that the certificate is valid for | | url | string | Yes | The URL to navigate to after authentication | | certPath | string | No* | Path to the certificate file in PEM format | | keyPath | string | No* | Path to the private key file in PEM format | | pfxPath | string | No* | Path to the PFX/PKCS12 certificate file | | passphrase | string | No | Passphrase for the private key | | pfxBuffer | Buffer | No* | Direct value of the PFX/PKCS12 certificate | | certBuffer | Buffer | No* | Direct value of the certificate in PEM format | | keyBuffer | Buffer | No* | Direct value of the private key in PEM format | | timeout | number | No | Timeout in milliseconds for page load (default: 30000) |

* You must provide either:

  • pfxPath or pfxBuffer, OR
  • Both certPath and keyPath, OR
  • Both certBuffer and keyBuffer

Methods

| Method | Returns | Description | |--------|---------|-------------| | authenticate() | Promise | Authenticates using the provided client certificate | | getCookies() | Array | Returns the cookies obtained after authentication | | getHeaders() | Object | Returns the headers prepared for API calls | | getBrowser() | Browser | Returns the Playwright browser instance | | getContext() | BrowserContext | Returns the Playwright browser context | | getPage() | Page | Returns the Playwright page instance | | close() | Promise | Closes the browser instance |

Error Handling

The class will throw an error if:

  • Required options are missing
  • Certificate files cannot be read
  • Authentication process fails
  • Page load timeout is exceeded