@teploy/observe-browser 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Observe project
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,152 @@
1
- # Temporary Holding Version
1
+ # @teploy/observe-browser
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Browser SDK for [Observe](https://github.com/useteploy/teploy-observe) — self-hosted analytics, errors, logs, sessions.
4
+
5
+ ## Install
6
+
7
+ ```
8
+ npm install @teploy/observe-browser
9
+ ```
10
+
11
+ <!-- not-yet-published: delete this block once @teploy/observe-browser is on npm -->
12
+ > **Not yet published to npm.** Until it is, `npm install @teploy/observe-browser` fails
13
+ > with a 404, and a package of that name that appears on npm before this note
14
+ > is removed is not from this project. Build it from this repository instead:
15
+ >
16
+ > ```sh
17
+ > git clone https://github.com/useteploy/teploy-observe
18
+ > cd teploy-observe/sdk/browser
19
+ > npm ci && npm run build && npm pack
20
+ > # then, in your project:
21
+ > npm install /path/to/teploy-observe/sdk/browser/teploy-observe-browser-0.1.0.tgz
22
+ > ```
23
+ <!-- /not-yet-published -->
24
+
25
+ ## Usage
26
+
27
+ ```ts
28
+ import { init, track, captureException } from "@teploy/observe-browser";
29
+
30
+ init({
31
+ endpoint: "https://observe.example.com",
32
+ siteId: "default",
33
+ });
34
+
35
+ // Custom event. Props are sent nested under `properties`, which is the only
36
+ // place the server reads them from.
37
+ track("signup", { plan: "pro", source: "hacker_news" });
38
+
39
+ // Error capture (auto-captured from `window.onerror` / unhandledrejection too)
40
+ try {
41
+ risky();
42
+ } catch (err) {
43
+ captureException(err as Error, { release: "v1.4.2" });
44
+ }
45
+ ```
46
+
47
+ ## API
48
+
49
+ | fn | purpose |
50
+ |----|---------|
51
+ | `init(options)` | Initialize. Starts auto-pageview + buffered flush. |
52
+ | `pageview(pathname?)` | Record a pageview. |
53
+ | `track(type, props?)` | Record a custom event. Buffered. Props go to `properties` (max 50); the keys the server reads as fields — `url`, `referrer`, `title`, `language`, `screen`, `distinct_id`, `release` — stay top-level. |
54
+ | `identify(userId, traits?)` | Associate user id. |
55
+ | `reset()` | Clear user (on logout). |
56
+ | `captureException(err, ctx?)` | Send an error with stack trace. |
57
+ | `log(entry)` | Send a log line. |
58
+ | `flush()` | Force-flush buffered events. |
59
+ | `getStats()` | O11 diagnostics: delivered/retry/loss counters by reason, live queue depth, and the undelivered snapshot taken at pagehide. Null before init. |
60
+
61
+ ## Delivery, loss, and shutdown semantics
62
+
63
+ - **Bounded queue, explicit overflow policy.** The queue is capped in both
64
+ event count (200) and bytes (8 MiB) across buffered + pending. At
65
+ admission overflow the **newest** event is dropped; at the pending
66
+ retention cap (200 frozen requests) the **oldest** requests are dropped.
67
+ Every drop is reported through `onError` and counted in `getStats()`.
68
+ - **Retry.** Failed batches retry with doubling backoff (default 5
69
+ attempts, 1 s base, 60 s cap) and then count as `retry_exhausted` losses.
70
+ Per-record rejections inside an accepted batch (`rejected` in the server
71
+ ack) are counted as `server_rejected` and not retried — the accepted
72
+ neighbors must not be resent.
73
+ - **Shutdown.** `visibilitychange(hidden)` and `pagehide` trigger a
74
+ keepalive flush. At pagehide, still-queued events are snapshotted into
75
+ `getStats().undeliveredAtUnload` and reported via `onError` — the honest
76
+ upper bound, because the page may die before delivery confirmation.
77
+ - `kill`-class crashes lose the in-memory queue and its counters with the
78
+ page; no durable spool is claimed.
79
+
80
+ ## Options
81
+
82
+ | name | default | description |
83
+ |------|---------|-------------|
84
+ | `endpoint` | — | Required. Observe base URL. |
85
+ | `siteId` | `"default"`, or none with `apiKey` | Site identifier. Leave unset with an `apiKey`: the key is bound to one site and a different one is refused. |
86
+ | `apiKey` | — | API key for server-side ingest paths (errors, logs). |
87
+ | `disableAutoPageview` | `false` | Skip auto pageview on init. |
88
+ | `batchSize` | `50` | Buffer size before auto-flush. |
89
+ | `flushIntervalMs` | `2000` | Time-based flush interval. |
90
+ | `maxRetryAttempts` | `5` | Automatic retries per failed batch before it is dropped and reported via `onError`. |
91
+ | `retryBackoffMs` | `1000` | Base delay for the retry backoff; doubles per attempt up to 60 s. |
92
+ | `requestTimeoutMs` | `10000` | Per-request deadline for every flush send (clamped 250 ms–10 min). A slow endpoint aborts and retries rather than pinning the flush owner. |
93
+ | `onError` | — | Called with every delivery failure or drop (the SDK never throws). |
94
+ | `onRetry` | — | Called each time a failed batch is scheduled for an automatic retry. |
95
+
96
+ ## Breadcrumbs
97
+
98
+ Breadcrumbs are attached to `captureException` and `captureMessage`
99
+ payloads (wire fields: `type`, `category`, `message`, `data`, `timestamp` in
100
+ Unix ms, `level`). Automatic capture is **opt-in**; nothing is patched
101
+ unless you ask.
102
+
103
+ ```ts
104
+ init({
105
+ endpoint, apiKey,
106
+ breadcrumbs: { // or `true` for all defaults
107
+ maxBreadcrumbs: 100, // ring buffer size (1..1000)
108
+ console: true, clicks: true, navigation: true, fetch: true, xhr: true,
109
+ clickText: false, // click data never includes text unless true
110
+ beforeBreadcrumb: (c) => (c.category === "console" ? null : c), // edit or drop
111
+ },
112
+ });
113
+ addBreadcrumb({ category: "checkout", message: "coupon applied", data: { code: "X" } });
114
+ await captureMessage("slow render", { level: "warning" });
115
+ ```
116
+
117
+ - console: `log/info/warn/error/debug`; arguments are stringified (256 chars).
118
+ Console output can contain personal data: scrub with `beforeBreadcrumb`.
119
+ - clicks: `tag#id.class` only. Element text is excluded by default.
120
+ - navigation: `pushState`, `replaceState`, `popstate`, `hashchange`; URLs are origin+path.
121
+ - fetch / XHR: method, status, URL without query or fragment. The SDK's own
122
+ endpoint is never recorded.
123
+ - Patches are reversible (restored on re-init), never throw into host code,
124
+ call the original with its original `this` and arguments, and are skipped
125
+ when there is no `window` (SSR). A `beforeBreadcrumb` that throws drops the crumb.
126
+ - `addBreadcrumb` / `clearBreadcrumbs` work without automatic capture.
127
+
128
+ ## Feature flags
129
+
130
+ ```ts
131
+ const r = await evaluateFlag("new-checkout", {
132
+ attributes: { plan: "pro" }, // sent as strings; userId defaults to identify()
133
+ default: { enabled: false }, // returned on ANY failure
134
+ });
135
+ if (r.enabled) { /* r.variant, r.source: "server" | "cache" | "default" */ }
136
+ const all = await evaluateFlags(["a", "b"], { default: { enabled: false } });
137
+ ```
138
+
139
+ Calls `POST /api/v1/flags/evaluate` (public route, rate limited). Results are
140
+ cached in memory (30 s, `init({ flags: { ttlMs, timeoutMs } })`), identical
141
+ in-flight calls are coalesced, and requests time out after 3 s. It never
142
+ rejects: network errors, timeouts, non-2xx, malformed bodies and server
143
+ fail-safe answers (`reason` `unavailable`/`invalid`) resolve to your `default`
144
+ with `source: "default"` and `error` set, and are not cached. **No exposure is
145
+ recorded** unless you pass `exposure: true` (one `flag_exposure` event per
146
+ flag/user/variant) or call `track()` where the variant is rendered. Use
147
+ `createFlagClient({ endpoint, siteId })` for a standalone client. See
148
+ `docs/sdk/BREADCRUMBS_FLAGS.md`.
149
+
150
+ ## License
151
+
152
+ MIT
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Breadcrumb recorder for @teploy/observe-browser.
3
+ *
4
+ * A breadcrumb is a small record of something that happened before an
5
+ * error. The wire shape matches what the server's error ingest accepts
6
+ * (internal/errors Breadcrumb): `type`, `category`, `message`, `data`,
7
+ * `timestamp` (Unix ms), `level`.
8
+ *
9
+ * Automatic capture is OPT-IN (`init({ breadcrumbs: true })`). Every patch
10
+ * the recorder installs is reversible: `uninstall()` restores the original
11
+ * function when the SDK's wrapper is still the outermost one, and otherwise
12
+ * turns the wrapper into a pass-through so a later patcher (another
13
+ * monitoring tool) is never broken by teardown order. No wrapper ever
14
+ * throws into host code: recording is wrapped in try/catch and the
15
+ * original call always runs, with its original `this`, arguments and
16
+ * return value.
17
+ */
18
+ export type BreadcrumbLevel = "debug" | "info" | "warning" | "error";
19
+ export interface Breadcrumb {
20
+ /** Coarse kind: "default", "console", "user", "navigation", "http". */
21
+ type: string;
22
+ /** Finer label: "console", "click", "navigation", "fetch", "xhr", or your own. */
23
+ category: string;
24
+ message: string;
25
+ /** JSON-serializable detail. Oversized or non-serializable data is replaced. */
26
+ data?: Record<string, unknown>;
27
+ /** Unix epoch milliseconds. */
28
+ timestamp: number;
29
+ level?: BreadcrumbLevel;
30
+ }
31
+ /** Fields a caller supplies to addBreadcrumb(); timestamp defaults to now. */
32
+ export type BreadcrumbInput = Partial<Omit<Breadcrumb, "message">> & {
33
+ message: string;
34
+ };
35
+ export interface BreadcrumbOptions {
36
+ /** Ring buffer size. Default 100; clamped to [1, 1000]. */
37
+ maxBreadcrumbs?: number;
38
+ /** Record console.log/info/warn/error/debug. Default true. */
39
+ console?: boolean;
40
+ /** Record clicks (tag, id, classes; no text). Default true. */
41
+ clicks?: boolean;
42
+ /** Include the clicked element's text (first 64 chars) in click data.
43
+ * Default false: text content can carry personal data. */
44
+ clickText?: boolean;
45
+ /** Record pushState/replaceState/popstate/hashchange navigation. Default true. */
46
+ navigation?: boolean;
47
+ /** Record fetch calls (method, status, url without query). Default true. */
48
+ fetch?: boolean;
49
+ /** Record XMLHttpRequest calls (method, status, url without query). Default true. */
50
+ xhr?: boolean;
51
+ /** Last chance to edit or drop a breadcrumb. Return null/undefined to
52
+ * drop it. Applies to manual and automatic breadcrumbs alike. A hook
53
+ * that throws drops the breadcrumb (fail closed: it is usually a scrubber). */
54
+ beforeBreadcrumb?: (crumb: Breadcrumb) => Breadcrumb | null | undefined;
55
+ /** URL prefixes whose HTTP calls are never recorded. The SDK adds its
56
+ * own ingest endpoint here so it cannot record its own traffic. */
57
+ ignoreUrls?: string[];
58
+ }
59
+ export declare const DEFAULT_MAX_BREADCRUMBS = 100;
60
+ /** Strip query, fragment and credentials; keep origin+path (F41 contract). */
61
+ export declare function sanitizeUrl(raw: unknown): string;
62
+ export interface BreadcrumbRecorder {
63
+ add(input: BreadcrumbInput): void;
64
+ /** Oldest-first copy, bounded to the attach byte budget. */
65
+ snapshot(): Breadcrumb[];
66
+ clear(): void;
67
+ /** Install automatic capture. Idempotent. Returns false without a window. */
68
+ install(): boolean;
69
+ /** Remove every patch and listener this recorder installed. Idempotent. */
70
+ uninstall(): void;
71
+ readonly installed: boolean;
72
+ }
73
+ /** Describe a DOM element without its text: `button#save.btn.primary`. */
74
+ export declare function describeElement(el: any): {
75
+ message: string;
76
+ data: Record<string, unknown>;
77
+ };
78
+ export declare function createRecorder(options?: BreadcrumbOptions, report?: (err: Error) => void): BreadcrumbRecorder;
79
+ //# sourceMappingURL=breadcrumbs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breadcrumbs.d.ts","sourceRoot":"","sources":["../src/breadcrumbs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CA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D;IAC5D,QAAQ,IAAI,UAAU,EAAE,CAAC;IACzB,KAAK,IAAI,IAAI,CAAC;IACd,6EAA6E;IAC7E,OAAO,IAAI,OAAO,CAAC;IACnB,2EAA2E;IAC3E,SAAS,IAAI,IAAI,CAAC;IAClB,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAID,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,EAAE,EAAE,GAAG,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAc3F;AAED,wBAAgB,cAAc,CAAC,OAAO,GAAE,iBAAsB,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,GAAG,kBAAkB,CAgPjH"}
@@ -0,0 +1,363 @@
1
+ /**
2
+ * Breadcrumb recorder for @teploy/observe-browser.
3
+ *
4
+ * A breadcrumb is a small record of something that happened before an
5
+ * error. The wire shape matches what the server's error ingest accepts
6
+ * (internal/errors Breadcrumb): `type`, `category`, `message`, `data`,
7
+ * `timestamp` (Unix ms), `level`.
8
+ *
9
+ * Automatic capture is OPT-IN (`init({ breadcrumbs: true })`). Every patch
10
+ * the recorder installs is reversible: `uninstall()` restores the original
11
+ * function when the SDK's wrapper is still the outermost one, and otherwise
12
+ * turns the wrapper into a pass-through so a later patcher (another
13
+ * monitoring tool) is never broken by teardown order. No wrapper ever
14
+ * throws into host code: recording is wrapped in try/catch and the
15
+ * original call always runs, with its original `this`, arguments and
16
+ * return value.
17
+ */
18
+ export const DEFAULT_MAX_BREADCRUMBS = 100;
19
+ const MAX_MESSAGE = 256;
20
+ const MAX_DATA_BYTES = 1024;
21
+ /** Budget for the breadcrumbs attached to one payload; oldest are dropped first. */
22
+ const MAX_ATTACH_BYTES = 32 * 1024;
23
+ function clampInt(v, dflt, min, max) {
24
+ const n = typeof v === "number" && Number.isFinite(v) ? Math.floor(v) : dflt;
25
+ return Math.min(max, Math.max(min, n));
26
+ }
27
+ function truncate(s, n) {
28
+ return s.length > n ? s.slice(0, n) : s;
29
+ }
30
+ /** Strip query, fragment and credentials; keep origin+path (F41 contract). */
31
+ export function sanitizeUrl(raw) {
32
+ if (typeof raw !== "string" || raw === "")
33
+ return "";
34
+ try {
35
+ const base = typeof location !== "undefined" && location.href ? location.href : undefined;
36
+ const u = base ? new URL(raw, base) : new URL(raw);
37
+ if (u.protocol !== "http:" && u.protocol !== "https:")
38
+ return "";
39
+ return u.origin + u.pathname;
40
+ }
41
+ catch {
42
+ // Unparseable: cut at the first ? or # as a last resort.
43
+ return truncate(raw.split(/[?#]/)[0], 256);
44
+ }
45
+ }
46
+ function safeStringify(v) {
47
+ if (typeof v === "string")
48
+ return v;
49
+ if (v instanceof Error)
50
+ return `${v.name}: ${v.message}`;
51
+ if (v === undefined)
52
+ return "undefined";
53
+ try {
54
+ const s = JSON.stringify(v);
55
+ return s === undefined ? String(v) : s;
56
+ }
57
+ catch {
58
+ try {
59
+ return String(v);
60
+ }
61
+ catch {
62
+ return "[unprintable]";
63
+ }
64
+ }
65
+ }
66
+ /** Own-data snapshot: JSON round trip, size-capped. Returns undefined when
67
+ * the data cannot be represented. */
68
+ function cloneData(data) {
69
+ if (data === null || typeof data !== "object")
70
+ return undefined;
71
+ try {
72
+ const raw = JSON.stringify(data);
73
+ if (raw === undefined)
74
+ return undefined;
75
+ if (raw.length > MAX_DATA_BYTES)
76
+ return { _truncated: true, _bytes: raw.length };
77
+ const parsed = JSON.parse(raw);
78
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : { value: parsed };
79
+ }
80
+ catch {
81
+ return { _unserializable: true };
82
+ }
83
+ }
84
+ const LEVELS = new Set(["debug", "info", "warning", "error"]);
85
+ /** Describe a DOM element without its text: `button#save.btn.primary`. */
86
+ export function describeElement(el) {
87
+ const tag = typeof el?.tagName === "string" ? el.tagName.toLowerCase() : "unknown";
88
+ const id = typeof el?.id === "string" && el.id ? el.id : "";
89
+ let classes = [];
90
+ const cn = el?.className;
91
+ if (typeof cn === "string")
92
+ classes = cn.split(/\s+/).filter(Boolean);
93
+ classes = classes.slice(0, 3).map((c) => truncate(c, 40));
94
+ const message = truncate(tag + (id ? "#" + truncate(id, 60) : "") + classes.map((c) => "." + c).join(""), 128);
95
+ const data = { tag };
96
+ if (id)
97
+ data.id = truncate(id, 60);
98
+ if (classes.length)
99
+ data.classes = classes;
100
+ const role = typeof el?.getAttribute === "function" ? el.getAttribute("role") : null;
101
+ if (typeof role === "string" && role)
102
+ data.role = truncate(role, 40);
103
+ return { message, data };
104
+ }
105
+ export function createRecorder(options = {}, report) {
106
+ const max = clampInt(options.maxBreadcrumbs, DEFAULT_MAX_BREADCRUMBS, 1, 1000);
107
+ const ignore = (options.ignoreUrls ?? []).filter((u) => typeof u === "string" && u !== "");
108
+ const ring = [];
109
+ const undo = [];
110
+ let active = false;
111
+ function add(input) {
112
+ try {
113
+ if (!input || typeof input.message !== "string")
114
+ return;
115
+ let crumb = {
116
+ type: truncate(String(input.type ?? "default"), 64),
117
+ category: truncate(String(input.category ?? "default"), 64),
118
+ message: truncate(input.message, MAX_MESSAGE),
119
+ timestamp: typeof input.timestamp === "number" && Number.isFinite(input.timestamp)
120
+ ? Math.floor(input.timestamp)
121
+ : Date.now(),
122
+ level: LEVELS.has(String(input.level)) ? input.level : "info",
123
+ };
124
+ const data = cloneData(input.data);
125
+ if (data)
126
+ crumb.data = data;
127
+ if (options.beforeBreadcrumb) {
128
+ let out;
129
+ try {
130
+ out = options.beforeBreadcrumb(crumb);
131
+ }
132
+ catch (err) {
133
+ report?.(err instanceof Error ? err : new Error(String(err)));
134
+ return;
135
+ }
136
+ if (!out)
137
+ return;
138
+ // Re-normalize: the hook may hand back anything.
139
+ crumb = {
140
+ type: truncate(String(out.type ?? crumb.type), 64),
141
+ category: truncate(String(out.category ?? crumb.category), 64),
142
+ message: truncate(String(out.message ?? ""), MAX_MESSAGE),
143
+ timestamp: typeof out.timestamp === "number" && Number.isFinite(out.timestamp) ? Math.floor(out.timestamp) : crumb.timestamp,
144
+ level: LEVELS.has(String(out.level)) ? out.level : crumb.level,
145
+ };
146
+ const d = cloneData(out.data);
147
+ if (d)
148
+ crumb.data = d;
149
+ }
150
+ ring.push(crumb);
151
+ if (ring.length > max)
152
+ ring.splice(0, ring.length - max);
153
+ }
154
+ catch {
155
+ /* recording must never throw into host code */
156
+ }
157
+ }
158
+ function snapshot() {
159
+ const out = [];
160
+ let bytes = 2;
161
+ for (let i = ring.length - 1; i >= 0; i--) {
162
+ const c = ring[i];
163
+ const size = JSON.stringify(c).length + 1;
164
+ if (bytes + size > MAX_ATTACH_BYTES)
165
+ break;
166
+ bytes += size;
167
+ out.push({ ...c, ...(c.data ? { data: { ...c.data } } : {}) });
168
+ }
169
+ return out.reverse();
170
+ }
171
+ /** Replace obj[name] with wrap(original); reversible and chain-safe. */
172
+ function patch(obj, name, wrap) {
173
+ if (!obj || typeof obj[name] !== "function")
174
+ return;
175
+ const orig = obj[name];
176
+ let wrapper;
177
+ try {
178
+ wrapper = wrap(orig);
179
+ obj[name] = wrapper;
180
+ }
181
+ catch {
182
+ return;
183
+ }
184
+ if (obj[name] !== wrapper)
185
+ return; // frozen/readonly: nothing was patched
186
+ undo.push(() => {
187
+ try {
188
+ if (obj[name] === wrapper)
189
+ obj[name] = orig;
190
+ }
191
+ catch {
192
+ /* restore best-effort */
193
+ }
194
+ });
195
+ }
196
+ function ignored(url) {
197
+ for (const p of ignore)
198
+ if (url.startsWith(p))
199
+ return true;
200
+ return false;
201
+ }
202
+ function listen(target, type, fn, capture = false) {
203
+ if (!target || typeof target.addEventListener !== "function")
204
+ return;
205
+ target.addEventListener(type, fn, capture);
206
+ undo.push(() => {
207
+ try {
208
+ target.removeEventListener(type, fn, capture);
209
+ }
210
+ catch {
211
+ /* ignore */
212
+ }
213
+ });
214
+ }
215
+ function install() {
216
+ if (active)
217
+ return true;
218
+ if (typeof window === "undefined")
219
+ return false;
220
+ active = true;
221
+ const w = window;
222
+ if (options.console !== false && typeof console !== "undefined") {
223
+ const levels = [
224
+ ["log", "info"], ["info", "info"], ["warn", "warning"], ["error", "error"], ["debug", "debug"],
225
+ ];
226
+ for (const [name, level] of levels) {
227
+ patch(console, name, (orig) => function (...args) {
228
+ if (active) {
229
+ try {
230
+ add({ type: "console", category: "console", level, message: args.map(safeStringify).join(" ") });
231
+ }
232
+ catch { /* never throw */ }
233
+ }
234
+ return orig.apply(this, args);
235
+ });
236
+ }
237
+ }
238
+ if (options.clicks !== false) {
239
+ listen(typeof document !== "undefined" ? document : null, "click", (e) => {
240
+ if (!active)
241
+ return;
242
+ try {
243
+ const t = e?.target;
244
+ if (!t)
245
+ return;
246
+ const d = describeElement(t);
247
+ if (options.clickText === true && typeof t.textContent === "string") {
248
+ const text = t.textContent.trim().slice(0, 64);
249
+ if (text)
250
+ d.data.text = text;
251
+ }
252
+ add({ type: "user", category: "click", message: d.message, data: d.data });
253
+ }
254
+ catch { /* never throw */ }
255
+ }, true);
256
+ }
257
+ if (options.navigation !== false) {
258
+ const cur = () => (typeof location !== "undefined" ? sanitizeUrl(location.href) : "");
259
+ let last = cur();
260
+ const nav = () => {
261
+ if (!active)
262
+ return;
263
+ try {
264
+ const to = cur();
265
+ if (to === last)
266
+ return;
267
+ add({ type: "navigation", category: "navigation", message: to, data: { from: last, to } });
268
+ last = to;
269
+ }
270
+ catch { /* never throw */ }
271
+ };
272
+ const h = typeof history !== "undefined" ? history : null;
273
+ for (const name of ["pushState", "replaceState"]) {
274
+ patch(h, name, (orig) => function (...args) {
275
+ const r = orig.apply(this, args);
276
+ nav();
277
+ return r;
278
+ });
279
+ }
280
+ listen(w, "popstate", nav);
281
+ listen(w, "hashchange", nav);
282
+ }
283
+ if (options.fetch !== false && typeof w.fetch === "function") {
284
+ patch(w, "fetch", (orig) => function (...args) {
285
+ let method = "GET";
286
+ let url = "";
287
+ let skip = true;
288
+ try {
289
+ const input = args[0];
290
+ const init = args[1];
291
+ const rawUrl = typeof input === "string" ? input : input && typeof input.url === "string" ? input.url : String(input ?? "");
292
+ method = String(init?.method ?? input?.method ?? "GET").toUpperCase();
293
+ url = sanitizeUrl(rawUrl);
294
+ skip = !active || url === "" || ignored(url) || ignored(rawUrl);
295
+ }
296
+ catch {
297
+ skip = true;
298
+ }
299
+ const p = orig.apply(this, args);
300
+ if (!skip && p && typeof p.then === "function") {
301
+ // Observe without altering the caller's promise; both branches
302
+ // swallow so this derived promise can never be unhandled.
303
+ p.then((res) => {
304
+ const status = typeof res?.status === "number" ? res.status : 0;
305
+ add({ type: "http", category: "fetch", level: status >= 400 ? "error" : "info", message: `${method} ${url}`, data: { method, url, status_code: status } });
306
+ }, (err) => {
307
+ add({ type: "http", category: "fetch", level: "error", message: `${method} ${url}`, data: { method, url, status_code: 0, error: truncate(safeStringify(err), 128) } });
308
+ });
309
+ }
310
+ return p;
311
+ });
312
+ }
313
+ const X = w.XMLHttpRequest;
314
+ if (options.xhr !== false && X && X.prototype) {
315
+ const meta = new WeakMap();
316
+ patch(X.prototype, "open", (orig) => function (...args) {
317
+ try {
318
+ const rawUrl = String(args[1] ?? "");
319
+ const url = sanitizeUrl(rawUrl);
320
+ meta.set(this, { method: String(args[0] ?? "GET").toUpperCase(), url, skip: url === "" || ignored(url) || ignored(rawUrl) });
321
+ }
322
+ catch { /* never throw */ }
323
+ return orig.apply(this, args);
324
+ });
325
+ patch(X.prototype, "send", (orig) => function (...args) {
326
+ try {
327
+ const m = meta.get(this);
328
+ if (m && !m.skip && typeof this.addEventListener === "function") {
329
+ const done = () => {
330
+ if (!active)
331
+ return;
332
+ const status = typeof this.status === "number" ? this.status : 0;
333
+ add({ type: "http", category: "xhr", level: status === 0 || status >= 400 ? "error" : "info", message: `${m.method} ${m.url}`, data: { method: m.method, url: m.url, status_code: status } });
334
+ };
335
+ this.addEventListener("loadend", done, { once: true });
336
+ }
337
+ }
338
+ catch { /* never throw */ }
339
+ return orig.apply(this, args);
340
+ });
341
+ }
342
+ return true;
343
+ }
344
+ function uninstall() {
345
+ active = false;
346
+ while (undo.length) {
347
+ const fn = undo.pop();
348
+ try {
349
+ fn();
350
+ }
351
+ catch { /* ignore */ }
352
+ }
353
+ }
354
+ return {
355
+ add,
356
+ snapshot,
357
+ clear: () => { ring.length = 0; },
358
+ install,
359
+ uninstall,
360
+ get installed() { return active; },
361
+ };
362
+ }
363
+ //# sourceMappingURL=breadcrumbs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"breadcrumbs.js","sourceRoot":"","sources":["../src/breadcrumbs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AA6CH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAC3C,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,oFAAoF;AACpF,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAC;AAEnC,SAAS,QAAQ,CAAC,CAAU,EAAE,IAAY,EAAE,GAAW,EAAE,GAAW;IAClE,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7E,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,QAAQ,CAAC,CAAS,EAAE,CAAS;IACpC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,WAAW,CAAC,GAAY;IACtC,IAAI,OAAO,GAAG,KAAK,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