bugsnap

guide ยท next.js

How to add a free bug report widget to Next.js

Drop BugSnap's single <Script> tag into app/layout.tsx with strategy="afterInteractive". It weighs 18 KB (about 8 KB gzipped), has zero dependencies, stays invisible until a visitor hits an error or dead click, and masks passwords and card fields before any screenshot.

1. install in the App Router (app/layout.tsx)

Create a free project on BugSnap (or self-host the MIT repo) to get your data-project-key, then add Next.js's built-in Script component to your root layout:

import Script from 'next/script';

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body>
        {children}
        <Script
          src="https://getbugsnap.pages.dev/widget.js"
          data-project-key={process.env.NEXT_PUBLIC_BUGSNAP_KEY}
          data-trigger="on-error"
          strategy="afterInteractive"
        />
      </body>
    </html>
  );
}

Set NEXT_PUBLIC_BUGSNAP_KEY in .env.local and in your host's environment variables. The widget does nothing if the key is missing, so preview builds without it stay silent.

2. install in the Pages Router (pages/_app.tsx)

If your app uses the Pages Router, place the same <Script> tag inside _app.tsx:

import type { AppProps } from 'next/app';
import Script from 'next/script';

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <Component {...pageProps} />
      <Script
        src="https://getbugsnap.pages.dev/widget.js"
        data-project-key={process.env.NEXT_PUBLIC_BUGSNAP_KEY}
        data-trigger="on-error"
        strategy="afterInteractive"
      />
    </>
  );
}

3. why on-error and pre-capture masking matter in Next.js

  • No Core Web Vitals hit: strategy="afterInteractive" loads the 18 KB script after hydration.
  • Catches silent Next.js failures: uncaught client errors, unhandled promise rejections, failed /api/* calls (404, 422, 429 and 5xx), broken images, UI freezes and dead clicks, even when nobody clicks a button.
  • Safe on login and Stripe checkout: password, email, phone and card inputs and Stripe, Braintree and PayPal iframes are masked before the screenshot is drawn, and tokens and emails are scrubbed from error text. Add data-bugsnap-mask to any element you want hidden.
  • One-click fix in Cursor or Claude Code: every report has Copy as Markdown, or can open a GitHub Issue automatically. Need to format a bug by hand right now? Try the free bug report to AI prompt generator.

Want the details? Read how BugSnap masks cards, passwords and tokens before a screenshot exists, and how to turn live bug reports into prompts for AI coding agents.

frequently asked questions

Does BugSnap work with the Next.js App Router and Server Components?

Yes. It loads through next/script in app/layout.tsx, so you do not need a use client wrapper or a React context provider.

Will it slow down my Next.js Lighthouse score?

No. The script is 18 KB minified (about 8 KB gzipped), has zero runtime dependencies, and loads afterInteractive, after the page is already usable.

How much does BugSnap cost for a Next.js SaaS?

$0 forever on the free hosted tier (up to 5 projects and 100 reports a month), or unlimited when self-hosted under the MIT license on Cloudflare Workers + D1 or Node.

add bugsnap in one line.

$0 free forever and MIT open source. Hidden until a real bug, privacy masking always on.

<script src="https://getbugsnap.pages.dev/widget.js" data-project-key="YOUR_PROJECT_KEY" data-trigger="on-error" defer></script>