πŸš€ Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more β†’
Sign In

ghostbug

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ghostbug

Zero-config automatic bug context collector SDK for the browser

beta
Source
npmnpm
Version
0.2.0-beta.0
Version published
Weekly downloads
2
-83.33%
Maintainers
1
Weekly downloads
Β 
Created
Source

ghostbug

Zero-config automatic bug context collector for the browser. Drop it in, forget about it. When something breaks, you already have everything you need.

npm version bundle size license

Why ghostbug?

Testers spend 90% of their time manually collecting bug context β€” screenshots, error messages, console logs, steps to reproduce. ghostbug eliminates that by silently capturing everything in the background.

Sentry / LogRocketghostbug
SetupAccount, API keys, configghostbug.init()
Server neededYes (paid)No β€” everything local
Bundle size50-200KB+~7KB gzipped
DependenciesMultipleZero
OutputDashboard (another tab)JSON / Markdown you paste into GitHub Issues

Install

npm install ghostbug

Quick Start

import ghostbug from "ghostbug";

ghostbug.init();

That's it. ghostbug now auto-captures:

  • JS errors β€” window.onerror + unhandled promise rejections
  • Console errors β€” console.error() and console.warn()
  • Failed network requests β€” fetch and XMLHttpRequest (4xx/5xx)
  • User click trail β€” last 20 clicks with element selectors
  • Page context β€” URL, browser, viewport, timestamp

API

ghostbug.init(options?)

Initialize ghostbug. Call once when your app loads.

ghostbug.init({
  // Show floating widget UI (default: false)
  widget: true,

  // Or with widget options
  widget: {
    position: "bottom-right", // 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'
    collapsed: true,
    zIndex: 2147483647,
  },

  // Toggle individual collectors (all true by default)
  collectors: {
    errors: true,
    console: true,
    network: true,
    clicks: true,
  },

  // Max reports stored (oldest dropped when full)
  maxReports: 50,

  // Max breadcrumb trail per report
  maxBreadcrumbs: 20,

  // Rate limiting (prevent flood from error loops)
  rateLimit: { maxEvents: 10, windowMs: 1000 },

  // Filter/transform reports before storage
  beforeReport: (report) => {
    // Return false to discard
    // Return modified report to transform
    return report;
  },
});

ghostbug.getReports()

Returns all captured bug reports as an array.

const reports = ghostbug.getReports();
console.log(reports);

ghostbug.toMarkdown()

Returns a GitHub/Jira-ready markdown string of all captured bugs.

const md = ghostbug.toMarkdown();
// Paste into GitHub Issues, Jira, Slack, etc.

Example output:

## 1. TypeError: Cannot read property 'id' of undefined

- **Type:** error
- **Time:** 2026-02-23T10:21:33.000Z
- **Occurrences:** 3
- **URL:** https://myapp.com/dashboard
- **Browser:** Chrome 122

### Stack Trace
TypeError: Cannot read property 'id' of undefined
    at UserProfile (app.js:42:12)

### Breadcrumbs
| Time | Category | Event |
|------|----------|-------|
| 10:21:30 | click | Clicked button "Save" |
| 10:21:31 | network | POST /api/user -> 500 |
| 10:21:33 | error | TypeError: Cannot read... |

ghostbug.download(filename?)

Downloads all reports as a JSON file.

ghostbug.download(); // downloads ghostbug-report.json
ghostbug.download("my-bugs.json"); // custom filename

ghostbug.onBug(callback)

Subscribe to bugs in real-time. Returns an unsubscribe function.

const unsubscribe = ghostbug.onBug((report) => {
  // Send to Slack
  fetch("/api/slack-webhook", {
    method: "POST",
    body: JSON.stringify({ text: report.payload.message }),
  });
});

// Later: stop listening
unsubscribe();

ghostbug.destroy()

Teardown everything β€” removes all listeners, restores patched APIs, unmounts widget.

ghostbug.destroy();

Framework Integration

React / Next.js

"use client"; // Next.js App Router

import { useEffect } from "react";
import ghostbug from "ghostbug";

export default function GhostbugProvider({ children }) {
  useEffect(() => {
    ghostbug.init({ widget: true });
    return () => ghostbug.destroy();
  }, []);

  return <>{children}</>;
}
// layout.tsx
import GhostbugProvider from "./components/GhostbugProvider";

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <GhostbugProvider>{children}</GhostbugProvider>
      </body>
    </html>
  );
}

Vue

// main.ts
import ghostbug from "ghostbug";

ghostbug.init({ widget: true });

Plain HTML

<script src="https://unpkg.com/ghostbug/dist/index.iife.js"></script>
<script>
  ghostbug.default.init({ widget: true });
</script>

Widget

Enable the floating widget for testers β€” a small bug icon that shows captured bugs with copy/export buttons.

ghostbug.init({ widget: true });

The widget:

  • Shows a bug count badge
  • Click to expand and see all captured bugs
  • Copy MD β€” copies markdown to clipboard
  • Export β€” downloads JSON file
  • Uses Shadow DOM β€” styles never leak into your app
  • Fully isolated β€” your CSS won't break it

Bug Report Structure

Each captured bug contains:

{
  id: string;              // Unique report ID
  fingerprint: string;     // Hash for deduplication
  type: "error" | "console" | "network";
  timestamp: string;       // ISO 8601
  count: number;           // Occurrences (deduped)
  payload: { ... };        // Error details
  breadcrumbs: [ ... ];    // Events leading up to the bug
  context: {
    url: string;
    userAgent: string;
    viewport: { width, height };
    // ...
  };
}

How It Works

  • Error capture β€” Patches window.onerror and listens for unhandledrejection
  • Console capture β€” Monkey-patches console.error / console.warn (always calls originals)
  • Network capture β€” Patches fetch and XMLHttpRequest (only captures 4xx/5xx, never alters responses)
  • Click tracking β€” Uses capture-phase click listener (catches clicks even with stopPropagation)
  • Deduplication β€” Identical errors increment a counter instead of creating duplicate reports
  • Rate limiting β€” Token-bucket algorithm prevents floods from error loops
  • Ring buffer β€” Fixed-capacity storage prevents memory leaks in long-running apps
  • Safe teardown β€” destroy() restores all original APIs

Development

# Install dependencies
npm install

# Build (ESM + CJS + IIFE)
npm run build

# Run tests
npm test

# Watch mode
npm run test:watch

# Type check
npm run typecheck

# Lint
npm run lint

License

MIT

Keywords

bug

FAQs

Package last updated on 23 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts