# errorgap for Browser JavaScript / React

See [index.md](./index.md) for API details and the placeholder values (`ERRORGAP_API_KEY`, `ERRORGAP_ENDPOINT`, `ERRORGAP_PROJECT_SLUG`).

SDK source: `github.com/errorgaphq/errorgap-js` · current version: `0.1.1`.

## Install

```sh
npm install @errorgap/browser
```

Or drop in via CDN (UMD/IIFE exposes `window.Errorgap`):

```html
<script src="https://cdn.jsdelivr.net/npm/@errorgap/browser"></script>
<script>
  Errorgap.init({
    endpoint:    "https://errorgap.example.com",
    projectSlug: "your-project",
    apiKey:      "flk_...",
  });
</script>
```

## Configure

Import as early as possible in the app entry point:

```ts
import { Errorgap } from "@errorgap/browser";

Errorgap.init({
  endpoint:    "https://errorgap.example.com",
  projectSlug: "your-project",
  apiKey:      import.meta.env.VITE_ERRORGAP_API_KEY,
  environment: import.meta.env.MODE,
  release:     __APP_VERSION__,
});
```

The SDK hooks `window.error` and `window.unhandledrejection` automatically.

## React error boundary

```tsx
import { ErrorgapBoundary } from "@errorgap/browser/react";

export function App() {
  return (
    <ErrorgapBoundary fallback={<p>Something went wrong.</p>}>
      <Routes />
    </ErrorgapBoundary>
  );
}
```

## Trigger a test error

```ts
throw new Error("Errorgap test error");
```

In a React component, use a temporary button that throws.

## Verify

Run the verification curl from [index.md](./index.md) and confirm HTTP 201 with a `group_id`. Then throw the test error and confirm the onboarding screen advances.
