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

ff-test-firefox-bidi-client

v0.1.0

Published

Pure WebDriver BiDi client for Firefox automation

Downloads

9

Readme

firefox-bidi-client

Minimal WebDriver BiDi protocol client for Firefox. Provides low-level primitives for BiDi communication and Firefox process management - no high-level orchestration or abstractions.

Features

  • Minimal & focused - Just connection, commands, and events
  • Pure BiDi protocol - Direct WebSocket communication
  • Process management - Launch and manage Firefox instances
  • Zero dependencies (except ws for WebSocket)
  • TypeScript - Fully typed
  • Flexible logging - Bring your own logger

What This Package Does

  • BiDiConnection - WebSocket connection, send commands, receive responses/events
  • FirefoxProcessManager - Launch Firefox and discover BiDi port

What This Package Does NOT Do

  • No context management (that's your responsibility)
  • No navigation helpers (use browsingContext.navigate directly)
  • No high-level abstractions (use BiDi commands directly)
  • Build these in your application layer!

Installation

npm install firefox-bidi-client

Quick Start

import { BiDiConnection, FirefoxProcessManager } from 'firefox-bidi-client';

// Launch Firefox
const manager = new FirefoxProcessManager();
const port = await manager.launch({
  headless: true,
  viewport: { width: 1280, height: 720 },
});

// Connect to BiDi
const connection = new BiDiConnection();
await connection.connect(port);

// Get context
const tree = await connection.sendCommand('browsingContext.getTree', {});
const contextId = tree.contexts[0].context;

// Navigate
await connection.sendCommand('browsingContext.navigate', {
  context: contextId,
  url: 'https://example.com',
  wait: 'complete',
});

// Execute script
const result = await connection.sendCommand('script.evaluate', {
  expression: 'document.title',
  target: { context: contextId },
  awaitPromise: false,
});

console.log('Title:', result.result.value);

// Cleanup
await connection.close();
await manager.kill();

API Reference

BiDiConnection

Low-level BiDi WebSocket connection.

const connection = new BiDiConnection({
  connectionTimeout: 5000,  // Connection timeout (ms)
  commandTimeout: 10000,    // Command timeout (ms)
});

// Connect to BiDi endpoint
await connection.connect(port: number);

// Send command and get response
const result = await connection.sendCommand(method: string, params?: any);

// Subscribe to events
await connection.subscribe(events: string[], contexts?: string[]);

// Register event handler
connection.on('message', (event) => {
  if (event.method === 'log.entryAdded') {
    console.log('Console log:', event.params);
  }
});

// Check connection status
const connected = connection.isConnected();

// Close connection
await connection.close();

FirefoxProcessManager

Manage Firefox process lifecycle.

const manager = new FirefoxProcessManager();

// Launch Firefox and get BiDi port
const port = await manager.launch({
  firefoxPath?: string;           // Path to Firefox binary
  headless?: boolean;             // Run headless
  viewport?: { width, height };   // Window size
  profilePath?: string;           // Profile directory
  args?: string[];                // Additional args
  env?: Record<string, string>;   // Environment variables
  logFile?: string;               // Log output file
});

// Check if running
const running = manager.isRunning();

// Get port
const port = manager.getPort();

// Kill Firefox
await manager.kill();

Examples

Connect to existing Firefox

import { BiDiConnection } from 'firefox-bidi-client';

// Start Firefox manually with: firefox --remote-debugging-port=9222
const connection = new BiDiConnection();
await connection.connect(9222);

Subscribe to console events

connection.on('message', (event) => {
  if (event.method === 'log.entryAdded') {
    const { level, text } = event.params;
    console.log(`[${level}] ${text}`);
  }
});

await connection.subscribe(['log.entryAdded']);

Custom logger

import { setLogger, type Logger } from 'firefox-bidi-client';

const myLogger: Logger = {
  log: (msg) => console.log(msg),
  debug: (msg) => console.debug(msg),
  error: (msg, err) => console.error(msg, err),
};

setLogger(myLogger);

Design Philosophy

This package provides primitives, not abstractions. It handles:

  1. WebSocket connection to BiDi endpoint
  2. Command/response protocol
  3. Event forwarding
  4. Firefox process launching

You build the orchestration layer on top. This keeps the package:

  • Simple - Easy to understand and debug
  • Flexible - No imposed architecture
  • Focused - Does one thing well
  • Reusable - Works for any BiDi use case

BiDi Protocol Resources

License

MIT