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

gh-social-preview

v0.0.15

Published

CLI tool to screenshot a GitHub README and upload it as the repository social preview image.

Readme

gh-social-preview

Automate GitHub social preview image updates from your repository README.

This utility does two things:

  1. Captures a screenshot of https://github.com/<owner>/<repo>/blob/<default-branch>/README.md.
  2. Uploads that image to the repo's Settings -> Social preview.

It uses Playwright UI automation because this setting is managed in GitHub's web UI.

Requirements

  • Node.js 18+
  • A GitHub account that can edit the target repo settings (typically admin access)
  • Chromium installed for Playwright

Install

From npm (recommended):

npm i -g gh-social-preview
npx playwright install chromium

Or without global install:

npx gh-social-preview init-auth
npx gh-social-preview --repo owner/repo

From source:

npm install
npx playwright install chromium

Quick Start

  1. Authenticate once and save browser session state:
node gh-social-preview.js init-auth
  1. Update social preview from README screenshot:
node gh-social-preview.js --repo owner/repo

Usage

node gh-social-preview.js help

init-auth

node gh-social-preview.js init-auth [--storage-state /path/to/state.json] [--base-url https://github.com]

Options:

  • --storage-state (optional): Path where Playwright session JSON is saved.
    • Default: $XDG_STATE_HOME/gh-social-preview/auth/<host>.json
    • Fallback when XDG_STATE_HOME is unset: ~/.local/state/gh-social-preview/auth/<host>.json
  • --base-url (optional): GitHub base URL (for GitHub Enterprise, for example).

Notes:

  • Opens a visible browser window.
  • Waits until login is detected, then writes storage state.

Main command

node gh-social-preview.js --repo owner/repo [--storage-state /path/to/state.json] [options]

Required:

  • --repo: owner/repo or full repo URL.

Optional:

  • --base-url: Default https://github.com
  • --storage-state: Default $XDG_STATE_HOME/gh-social-preview/auth/<host>.json (fallback: ~/.local/state/gh-social-preview/auth/<host>.json; uses <host>=github for GitHub.com)
  • --width: Default 960
  • --height: Default 480
  • --format: png or jpeg (default jpeg)
  • --quality: JPEG quality 1-100 (default 80)
  • --out: Output path for screenshot (default $XDG_CACHE_HOME/gh-social-preview/images/<owner>__<repo>.<ext>, fallback ~/.cache/gh-social-preview/images/<owner>__<repo>.<ext>)
  • --headless: true|false (default true)

Examples

Update with visible browser and custom output:

node gh-social-preview.js \
  --repo AnswerDotAI/exhash \
  --headless false \
  --out .social-preview/exhash.jpg

Use against GitHub Enterprise:

node gh-social-preview.js init-auth \
  --base-url https://github.mycompany.com

node gh-social-preview.js \
  --base-url https://github.mycompany.com \
  --repo team/repo \
  --headless false

Behavior Notes

  • The screenshot is a viewport capture (not full page).
  • README capture resolves the repo default branch via the GitHub REST API (/repos/<owner>/<repo>), then targets blob/<default-branch>/README.md, waits for article.markdown-body, and hides GitHub's sticky blob header (Preview | Code | Blame) before taking the screenshot.
  • Upload supports both states:
    • no existing social card: adds a new one
    • existing social card: replaces it
  • If a JPEG output is over 1MB, the script retries with lower JPEG quality.
  • If PNG output is over 1MB, the script warns but does not auto-convert.
  • Upload completion primarily uses GitHub's upload response (/upload/repository-images/...) plus non-empty social-image id; unchanged id is accepted for identical-image replacements.

Troubleshooting

  • Redirected to /login during run:
    • Re-run init-auth and use the same base URL + storage-state path (or default host path).
  • Previously used ./.auth/<host>.json defaults:
    • Move that file to the XDG default path above (or pass --storage-state explicitly).
  • README container not found:
    • Repo likely does not have a root README.md on its default branch, or GitHub markup/layout changed.
  • Failed to query repo metadata from GitHub API:
    • Ensure the repository exists and is publicly accessible.
  • Upload controls not found:
    • GitHub UI may have changed; selectors in gh-social-preview.js may need updating.
  • Permission errors in settings:
    • Ensure your account has admin-level access for that repository.

Security

--storage-state contains authenticated browser session data. Treat it like a credential.

If you override defaults to store auth/screenshots in your repo, ignore those paths:

.auth/
.social-preview/

License

ISC