# Wire InsightRecorder capture into an htmx app

You are helping install the InsightRecorder **htmx adapter** in this repository.
It reports htmx request failures (a failed `hx-` swap) that htmx swallows and the
base capture agent never sees. It is an add-on to the browser agent, not a
replacement.

## Steps

1. Ensure the base capture agent is on the page (in the HTML `<head>`, in this
   order — `redact.js` first):

   ```html
   <script src="https://<HOST>/static/js/redact.js"></script>
   <script src="https://<HOST>/static/js/capture.js" data-token="<CAPTURE_TOKEN>" data-auto="error"></script>
   ```

   `<HOST>` is the InsightRecorder host; `<CAPTURE_TOKEN>` is the workspace's
   public capture token (Settings → Integrations).

2. Install the adapter and call `install()` after htmx is loaded:

   ```sh
   npm install @insightrecorder/capture-htmx
   ```

   ```js
   import { install } from "@insightrecorder/capture-htmx";
   install({ severity: "P1" });
   ```

   If the app has no bundler, expose the two module functions from a tiny script
   that runs after htmx, or copy the four event listeners inline (see below).

3. Optionally attach context so every report carries your release / flags:

   ```js
   window.insightRecorder.setContext({ build: "v2.41", custom: { plan } });
   ```

## What good looks like

- A `hx-post` that returns 500 (or a dropped connection / timeout) files a bug
  automatically, with the failing method + path in the title.
- A 4xx is on the capture timeline but does not file a bug (unless you pass
  `reportClientErrors: true`).
- htmx requests show as steps on the replay timeline.

## Verify before you finish

Trigger an endpoint that returns 500 from an `hx-` attribute, then confirm a new
bug appears in `/app/bugs` naming that request.

## Rules

- Never capture request bodies, headers, cookies, or the swapped HTML — the
  adapter only reads method/path/status.
- The adapter must be a no-op when the agent is absent; do not throw.
