Logged Docs
Logged Docs

Getting Started

  • Installation
  • Quick Start

SDK

  • Logger
  • Capture Errors
  • Browser Auto Capture
  • Console Capture

REST API

  • Overview

Examples

  • Next.js
  • React
  • JavaScript
Back to site
Back to SDK

Browser Auto Capture

Automatically capture uncaught browser errors and unhandled promise rejections with logger.auto().

Setup

typescript
import { Logged } from "@logged/sdk";

const logger = new Logged({
  apiKey: process.env.NEXT_PUBLIC_LOGGED_API_KEY!,
});

logger.auto();

Once enabled, Logged listens for global browser error events and sends them to the dashboard without any additional code.

What gets captured

  • Uncaught errors — errors thrown outside a try/catch block
  • Unhandled promise rejections — rejected promises without a catch handler

Example

typescript
// Somewhere in your app initialization
logger.auto();

// Later, an uncaught error will be sent automatically
throw new Error("Something went wrong");

Cleanup

typescript
logger.stopAutoCapture();

Call this when you no longer want Logged to listen for global errors, for example during tests or when tearing down a client-side application.

Next.js

Client only

Auto capture is a browser-only feature. Enable it inside a useEffect or a client component so it never runs during server rendering.
tsx
"use client";

import { useEffect } from "react";
import { Logged } from "@logged/sdk";

const logger = new Logged({
  apiKey: process.env.NEXT_PUBLIC_LOGGED_API_KEY!,
});

export function LoggedProvider() {
  useEffect(() => {
    logger.auto();
    return () => logger.stopAutoCapture();
  }, []);

  return null;
}