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

@justinhuangcode/browsercli

v1.0.4

Published

TypeScript/Node.js client for the browsercli browser workspace daemon

Downloads

540

Readme

browsercli Node.js Client

Zero-dependency Node.js client for the browsercli browser workspace daemon. Written in TypeScript with full type definitions included.

Installation

cd clients/node && npm install   # from the repo root

Platform Support

The client auto-detects the RPC transport from the session file:

  • macOS / Linux — connects via Unix socket (socket_path in session.json)
  • Windows — connects via TCP localhost (rpc_port in session.json)

No code changes are needed — BrowserCLI.connect() handles both transports.

Quick Start

import { BrowserCLI } from "@justinhuangcode/browsercli";

// Connect to a running daemon
// macOS/Linux: reads ~/.browsercli/session.json
// Windows: reads %LOCALAPPDATA%\browsercli\session.json
const ac = BrowserCLI.connect();

// Navigate and inspect
await ac.goto("/");
const title = await ac.domQuery("h1", "text");
console.log(`Title: ${title}`);

// Evaluate JavaScript
const result = await ac.eval("1 + 1");
console.log(`Result: ${result}`);

// Screenshot
await ac.screenshot("", "page.png");

// Stop the daemon
await ac.stop();

Error Handling

All exceptions inherit from BrowserCLIError, so you can catch the whole family or handle specific cases:

import {
  BrowserCLI,
  BrowserCLIError,
  ConnectionError,
  AuthenticationError,
  SessionError,
  NotFoundError,
  ServerError,
} from "@justinhuangcode/browsercli";

try {
  const ac = BrowserCLI.connect();
  await ac.domQuery("#missing-element", "text");
} catch (err) {
  if (err instanceof SessionError) {
    console.log("Daemon not running — start it with: browsercli start");
  } else if (err instanceof ConnectionError) {
    console.log("Cannot reach daemon — is the socket file valid?");
  } else if (err instanceof AuthenticationError) {
    console.log("Token rejected — daemon may have restarted, reconnect");
  } else if (err instanceof NotFoundError) {
    console.log(`Element or endpoint not found: ${err.errorMessage}`);
  } else if (err instanceof ServerError) {
    console.log(`Daemon internal error (HTTP ${err.statusCode}): ${err.errorMessage}`);
  } else if (err instanceof BrowserCLIError) {
    console.log(`Unexpected client error: ${err.message}`);
  }
}

Exception Hierarchy

BrowserCLIError            # Base — catch-all
├── SessionError            # session.json missing/invalid
├── ConnectionError         # RPC endpoint unreachable (socket or TCP)
├── AuthenticationError     # HTTP 401 (bad token)
└── RPCError                # Any HTTP 4xx/5xx with statusCode + errorMessage
    ├── BadRequestError     # HTTP 400
    ├── NotFoundError       # HTTP 404
    └── ServerError         # HTTP 5xx

Constructor

new BrowserCLI(addr: string, token: string, timeout?: number)

| Parameter | Type | Description | | --- | --- | --- | | addr | string | Unix socket path (macOS/Linux) or TCP host:port (Windows) | | token | string | Bearer token for daemon authentication | | timeout | number | Request timeout in ms (default 30000) |

In most cases, use the connect() factory instead of calling the constructor directly.

API Reference

| Method | Description | | --- | --- | | BrowserCLI.connect(sessionPath?, timeout?) | Create client from session file (auto-detects Unix socket or TCP) | | status() | Daemon and browser status | | version() | RPC and schema version info | | goto(url) | Navigate to a path or URL | | eval(expression) | Evaluate JavaScript | | reload() | Reload the page | | domQuery(selector, mode) | Query a single DOM element | | domAll(selector, mode) | Query all matching elements | | domAttr(selector, name) | Get an element attribute | | domClick(selector) | Click an element | | domType(selector, text, clear) | Type text into an input | | domWait(selector, state, timeoutMs) | Wait for element state | | screenshot(selector, out) | Capture screenshot (PNG Buffer) | | console(level, limit, clear) | Fetch console entries | | network(limit, clear) | Fetch network log entries | | perf() | Page performance metrics | | stop() | Stop the daemon | | pluginList() | List installed plugins | | pluginRpc(path, body?) | Call a custom plugin RPC endpoint (/x/...) |

All methods are async and return Promises.

Valid Parameter Values

| Parameter | Valid Values | Default | | --- | --- | --- | | domQuery / domAll mode | "outer_html", "text" | "outer_html" | | domWait state | "visible", "hidden", "attached", "detached" | "visible" | | console level | "" (all), "log", "warn", "error", "info" | "" |

Invalid values throw TypeError before any RPC call is made.

Running Tests

cd clients/node
npm test

Tests include:

  • Session parsing: valid/invalid/missing session files (including rpc_port for Windows)
  • Constructor validation: invalid addr, token, timeout
  • Parameter validation: client-side checks for all method arguments
  • Contract tests: mock HTTP server (Unix socket on macOS/Linux, TCP on Windows) emulating the Rust daemon
  • Error handling: auth failures, 400/404/500 errors, connection errors
  • Exception hierarchy: inheritance and attribute verification

Requirements

  • Node.js 18+
  • A running browsercli daemon (browsercli start)
  • No external dependencies (Node.js stdlib only)