# @biwave/browser

Browser integration SDK for Biwave error tracking, performance monitoring, and session replay (Biwave Stream).

## Features

- **Global Handlers:** Automatically captures `window.onerror` exceptions and `onunhandledrejection` promise errors.
- **Auto Breadcrumbs:** Captures DOM navigation, console logs, and `fetch`/XHR network calls.
- **Rich Context:** Enriches error events with browser, OS, device, screen resolution, viewport, and page URL details.
- **Optional Session Replay (Biwave Stream):** Lazy-loads `rrweb` dynamically when `stream.enabled: true` to record user sessions with built-in privacy masking and gzip compression.
- **IIFE Build:** Bundle available at `dist/index.global.js` (exposing global `window.Biwave`).

## Installation

```bash
# pnpm
pnpm add @biwave/browser @biwave/core

# npm
npm install @biwave/browser @biwave/core

# yarn
yarn add @biwave/browser @biwave/core
```

## Basic Usage

```typescript
import { init } from '@biwave/browser';

const client = init({
  clientId: 'your-client-id',
  environment: 'production',
  release: 'my-app@1.0.0',
});

// Manual exception capture
try {
  throw new Error('Something went wrong in browser');
} catch (err) {
  client.captureException(err);
}
```

## Session Replay (Biwave Stream)

Enable session replay by passing `stream: { enabled: true }` in options:

```typescript
import { init } from '@biwave/browser';

init({
  clientId: 'your-client-id',
  stream: {
    enabled: true,
    maskAllInputs: false,
    maskInputOptions: { password: true },
  },
});
```

_Note: `rrweb` is lazy-loaded only when `stream.enabled` is `true`, keeping initial bundle size minimal for standard error tracking._

## License

MIT © [Bitech.id](https://bitech.id)
