@newtalaria/browser 0.1.12 → 0.1.15

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/README.md CHANGED
@@ -59,6 +59,8 @@ Every ingested event includes browser runtime tags (`browser.name`, `browser.ver
59
59
 
60
60
  Optional init `tags` are merged into every captured event (per-call tags win on key conflict).
61
61
 
62
+ `environment` must resolve to a wire value: `production` | `staging` | `development`. Common aliases are accepted (`test`/`uat` → `staging`, `prod`/`live` → `production`, `dev`/`local` → `development`), matching the PHP SDK. Invalid values throw at `init`. Permanent `events/ingest` 4xx responses disable further capture for that page session so misconfig cannot spin forever.
63
+
62
64
  ## Script tag (IIFE)
63
65
 
64
66
  For hosts without a bundler (e.g. Silverstripe `Requirements`):
@@ -97,7 +99,8 @@ You pay for **uploaded + retained** bytes, not for local buffering. Prefer error
97
99
  | Mode | Behavior |
98
100
  | --- | --- |
99
101
  | Session sample hit | `replays/start` immediately; segments upload every ~5s or ~100KB until unload or **5 min** max |
100
- | Session sample miss | Record into a ~60s ring buffer; nothing uploaded until an error sample hits |
102
+ | Session sample miss | Record into a ~60s ring buffer with a FullSnapshot checkout every ~60s; nothing uploaded until an error sample hits |
103
+ | Tab hidden → visible / bfcache restore | Take a checkout FullSnapshot (background timers are throttled; refreshes the paint base so error clips still have lead-up) |
101
104
  | Error sample + `replaysErrorAfterMs > 0` | Upload buffer (≤~960KiB gzip pack target / **1MiB** server cap) + trailing window, hard caps **12 segments** or **2MiB** compressed, attach `replayId` only if segments landed, `finish`, return to buffer mode |
102
105
  | Error sample + `replaysErrorAfterMs = 0` | Upload buffer then continue like session mode until **5 min** / unload / size caps |
103
106
  | Server limit (replay segments / total size / duration) | Stop uploading that replay; no retries |
@@ -171,7 +174,7 @@ Segment payloads are a **gzip-compressed JSON array** of rrweb events.
171
174
 
172
175
  Custom rrweb events:
173
176
 
174
- - `talaria-console` — console level + args (truncated)
177
+ - `talaria-console` — console level + message/args (truncated)
175
178
  - `talaria-network` — method, redacted URL, status, duration (no bodies / no auth headers)
176
179
 
177
180
  Privacy defaults: `maskAllInputs: true`, password fields masked, `[data-talaria-mask]` blocked.
@@ -182,17 +185,25 @@ By default `inlineStylesheet` is `false`: linked stylesheets stay as `href`s and
182
185
 
183
186
  Set `inlineStylesheet: true` so same-origin stylesheet rules are embedded while the user is logged in. Cross-origin sheets without CORS still cannot be inlined (browser `cssRules` restriction).
184
187
 
185
- ### Failed HTTP requests → events
188
+ ### Failed HTTP / network requests → events
189
+
190
+ By default, completed `fetch` / XHR responses with status **500–599** are sent as Talaria events (message like `HTTP 500: GET /api/...`).
191
+
192
+ Transport failures (CORS, offline, DNS — browser `TypeError: Failed to fetch`) are also promoted by default as:
193
+
194
+ `Network error: GET https://… — TypeError: Failed to fetch`
186
195
 
187
- By default, completed `fetch` / XHR responses with status **500–599** are also sent as Talaria events (message like `HTTP 500: GET /api/...`). Replay still gets `talaria-network` breadcrumbs for all requests.
196
+ Replay `talaria-network` breadcrumbs include method, redacted URL, status (when present), duration, and on failures `errorName` / `errorMessage` / `aborted`. Request/response bodies and auth headers are never captured.
188
197
 
189
198
  ```ts
190
199
  Talaria.init({
191
200
  dsn: 'https://api.example.com',
192
201
  apiKey: 'tal_live_…',
193
202
  environment: 'production',
194
- // Default true
203
+ // Default true — HTTP status promotion
195
204
  captureFailedRequests: true,
205
+ // Default true — CORS/offline/DNS fetch failures
206
+ captureNetworkErrors: true,
196
207
  // Default [[500, 599]]. CMS admin often wants 4xx too:
197
208
  failedRequestStatusCodes: [[400, 599]],
198
209
  // Extra URL substrings to skip (Talaria /events and /replays are always skipped)
@@ -200,7 +211,7 @@ Talaria.init({
200
211
  });
201
212
  ```
202
213
 
203
- Transport errors (network down, no status) are not promoted as HTTP events; uncaught exceptions from failed fetches still go through normal `error` / `unhandledrejection` handlers when the app rethrows.
214
+ `AbortError` is never promoted and is ignored by the global `unhandledrejection` handler. If a fetch failure is left unhandled after network-error promotion, the duplicate bare `TypeError` event is suppressed; if promotion is off, the exception is kept and correlated with the recent request URL/method/duration.
204
215
 
205
216
  ## Public API
206
217
 
package/dist/client.d.ts CHANGED
@@ -36,6 +36,15 @@ export declare class TalariaClient {
36
36
  private lastReplayCaptureFailure;
37
37
  /** Cached once per init for event tags/extra. */
38
38
  private browserContext;
39
+ /** Prevent ingest/replay failures from being re-captured via unhandledrejection. */
40
+ private capturing;
41
+ /**
42
+ * Set after a permanent events/ingest 4xx (bad env/auth/wire). Further
43
+ * captures no-op so we don't spin on retries or burn error-clip replay quota.
44
+ */
45
+ private ingestDisabled;
46
+ /** Recent fetch/XHR transport failures for correlation + dedupe. */
47
+ private recentNetworkFailures;
39
48
  init(options: TalariaInitOptions): void;
40
49
  getReplayId(): string | null;
41
50
  captureException(error: unknown, context?: CaptureContext): Promise<void>;
@@ -52,6 +61,11 @@ export declare class TalariaClient {
52
61
  close(): Promise<void>;
53
62
  private onRrwebEvent;
54
63
  private capture;
64
+ /**
65
+ * Stop further event capture (and error-clip uploads) after a permanent
66
+ * events/ingest 4xx so misconfig cannot spin forever.
67
+ */
68
+ private disableIngestAfterPermanentError;
55
69
  private markUploadStarted;
56
70
  private isPastMaxDuration;
57
71
  private isPastErrorClipDeadline;
@@ -72,6 +86,12 @@ export declare class TalariaClient {
72
86
  private resetToBufferMode;
73
87
  /** Emit a checkout FullSnapshot into the ring buffer (sync via rrweb emit). */
74
88
  private checkoutFullSnapshot;
89
+ /**
90
+ * Tab focus / bfcache restore: background timers are throttled, so the
91
+ * buffer-mode checkout interval may not have fired. Refresh the paint base
92
+ * so an error clip still has ~60s of usable lead-up after the user returns.
93
+ */
94
+ private onForegroundResume;
75
95
  /**
76
96
  * Ensure segment 0 begins at Meta+FullSnapshot. Orphan increments alone
77
97
  * produce a blank rrweb player.
@@ -84,6 +104,13 @@ export declare class TalariaClient {
84
104
  */
85
105
  private abortUnusableClip;
86
106
  private stopUploadingAfterLimit;
107
+ private pruneRecentNetworkFailures;
108
+ private rememberNetworkFailure;
109
+ /**
110
+ * Find a recent transport failure for a bare fetch TypeError.
111
+ * Consumes the entry so a later duplicate path cannot reuse it.
112
+ */
113
+ private consumeCorrelatedNetworkFailure;
87
114
  private installGlobalHandlers;
88
115
  private enqueueUpload;
89
116
  private ensureStarted;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,aAAa,EACb,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAuDpB,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,0BAA0B,EAC1B,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,uBAAuB,EACvB,+BAA+B,EAC/B,+BAA+B,EAC/B,4BAA4B,GAC7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AA4ErC,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAAgC;IAC/C,OAAO,CAAC,SAAS,CAAmC;IACpD,OAAO,CAAC,QAAQ,CAAuB;IACvC,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,QAAQ,CAA+B;IAC/C,OAAO,CAAC,MAAM,CAAuB;IACrC,yEAAyE;IACzE,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,uBAAuB,CAAK;IACpC,0EAA0E;IAC1E,OAAO,CAAC,iBAAiB,CAAuB;IAChD,4EAA4E;IAC5E,OAAO,CAAC,mBAAmB,CAAuB;IAClD,OAA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