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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gobing-ai/ts-browser-automation

v0.8.9

Published

@gobing-ai/ts-browser-automation — Reusable Playwright persistent browser profile sessions: headed login, headless reuse.

Readme

@gobing-ai/ts-browser-automation

Reusable Playwright persistent browser profile sessions: sign in once with a dedicated visible Chromium profile, then drive later automation headless against the same profile. Extracted from knowledge-kit's XHS publish flow (task 0088, ADR-032).

Part of the @gobing-ai/ts-libs monorepo and lockstep-versioned with it.

  • License: Apache-2.0.
  • The package never stores usernames/passwords and never exports cookies — the Playwright user-data directory itself is the login artifact.

Install & runtime requirements

bun add @gobing-ai/ts-browser-automation
# Playwright is a required peer dependency (^1.55.0):
bun add playwright@^1.55.0
# Chromium is owned by the consumer (ADR-032):
npx playwright install chromium
  • Runtime: Node.js or Bun with Playwright's supported platforms.
  • A missing playwright peer or missing Chromium fails with a typed PlaywrightUnavailableError at launch time — never at import. Importing the module has no browser side effect.

Usage

1. One-time headed login into a dedicated profile

import { loginWithProfile } from '@gobing-ai/ts-browser-automation';

// You choose where the profile lives — the package has no default location.
const profileDir = `${process.env.HOME}/.local/share/myapp/browser-profiles/xhs`;

await loginWithProfile({
    profileDir,
    url: 'https://example-site.test/login',
    // Site-owned readiness check: only your predicate can declare success.
    isAuthenticated: async (page) => page.url().includes('/dashboard'),
    timeoutMs: 5 * 60_000,
});

A visible browser opens; sign in by hand. The context closes once your predicate passes — or on timeout, cancellation (signal), or error. If the deadline expires you get LoginTimeoutError with a re-login instruction; just run loginWithProfile again with the same profileDir.

2. Later automation reusing the authenticated profile

import { withProfilePage } from '@gobing-ai/ts-browser-automation';

const result = await withProfilePage(
    {
        profileDir,
        headless: true,
        url: 'https://example-site.test/feed',
        // Guard the claim of an authenticated session (task 0088 R3):
        isAuthenticated: (page) => page.url().includes('/feed'),
        timeoutMs: 30_000,
    },
    async ({ context, page }) => {
        // Full Playwright page/locator/upload APIs. Site-specific CDP is
        // caller-owned, e.g. for closed-shadow DOM control:
        const cdp = await context.newCDPSession(page);
        return page.locator('#app').innerText();
    },
);

withProfilePage guarantees context.close() in a finally on every exit path. For full manual control (e.g. keeping one context across many steps), use the low-level openPersistentBrowser({ profileDir, headless }) and close the returned BrowserContext yourself.

Behavior guarantees

  • Dedicated profile, explicit path. profileDir is required (empty/blank or an existing file → InvalidProfileDirError) and resolved to an absolute path. Relative input resolves against the current working directory.
  • Owner-only creation. A missing profile directory is created with 0o700 on a headed launch, on local filesystems that enforce permission bits (POSIX; mode bits are a no-op on Windows). Existing directories are adopted in place — never moved, re-permissioned, or deleted.
  • No silent unauthenticated sessions. A headless run against a missing profile fails with BrowserProfileMissingError instead of creating a fresh, unauthenticated one.
  • Single-process rule. Playwright user-data directories hold session state and cannot be opened by concurrent browser instances. One profile = one browser at a time; concurrent use surfaces as BrowserProfileBusyError.
  • Auth expiry is recoverable. A profile whose site session has expired fails the readiness predicate with LoginTimeoutError (message includes the re-login instruction) — it never reports a false authenticated result.
  • Sensitive material. Cookies and local storage in the profile are session material: never log profile contents, never commit a profile directory.

Caveats

  • Some sites reject headless automation. The headed path always remains available for debugging (headless: false or loginWithProfile); the package does not promise headless success on every site.
  • App-specific choices stay outside the package — no default profile location, site selectors, or credentials. Callers own all of them.

Manual smoke (local, never unattended)

  1. Pick a disposable account and a profile directory outside this repository: PROFILE="$HOME/tmp/smoke-profile-$$".
  2. Headed login: loginWithProfile({ profileDir: PROFILE, url: 'https://example-site.test/login', isAuthenticated: (p) => p.url().includes('/home'), timeoutMs: 300_000 }) — sign in manually, confirm the context closes after your predicate passes.
  3. Headless reuse: run the withProfilePage example above with headless: true and confirm the callback sees the authenticated page.
  4. Failure cases: re-run headless with a fresh non-existent PROFILE (expect BrowserProfileMissingError); open the same profile in a second browser and re-run (expect BrowserProfileBusyError); delete cookies via the site and re-run with the predicate (expect LoginTimeoutError).

Use a throwaway account. Do not run the headed-login step unattended or in CI.