@squasher-ai/browser 0.1.1 → 0.3.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.
Files changed (109) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +3 -42
  3. package/dist/_vendor/result-runtime/attempt.d.ts +17 -0
  4. package/dist/_vendor/result-runtime/attempt.js +62 -0
  5. package/dist/_vendor/sdk-runtime/batching/index.d.ts +42 -0
  6. package/dist/_vendor/sdk-runtime/batching/index.js +48 -0
  7. package/dist/_vendor/sdk-runtime/errors/headers.d.ts +6 -0
  8. package/dist/_vendor/sdk-runtime/errors/headers.js +44 -0
  9. package/dist/_vendor/sdk-runtime/errors/index.d.ts +95 -0
  10. package/dist/_vendor/sdk-runtime/errors/index.js +157 -0
  11. package/dist/_vendor/sdk-runtime/headers.d.ts +48 -0
  12. package/dist/_vendor/sdk-runtime/headers.js +67 -0
  13. package/dist/_vendor/sdk-runtime/platform.d.ts +33 -0
  14. package/dist/_vendor/sdk-runtime/platform.js +173 -0
  15. package/dist/_vendor/sdk-runtime/retry.d.ts +50 -0
  16. package/dist/_vendor/sdk-runtime/retry.js +104 -0
  17. package/dist/_vendor/sdk-runtime/runtime/actionable-error.d.ts +37 -0
  18. package/dist/_vendor/sdk-runtime/runtime/actionable-error.js +123 -0
  19. package/dist/_vendor/sdk-runtime/runtime/environment.d.ts +18 -0
  20. package/dist/_vendor/sdk-runtime/runtime/environment.js +81 -0
  21. package/dist/_vendor/sdk-runtime/runtime/public-sdk-runtime.d.ts +12 -0
  22. package/dist/_vendor/sdk-runtime/runtime/public-sdk-runtime.js +38 -0
  23. package/dist/_vendor/sdk-runtime/runtime/redaction.d.ts +14 -0
  24. package/dist/_vendor/sdk-runtime/runtime/redaction.js +120 -0
  25. package/dist/_vendor/sdk-runtime/runtime/release.d.ts +35 -0
  26. package/dist/_vendor/sdk-runtime/runtime/release.js +120 -0
  27. package/dist/_vendor/sdk-runtime/sampling/index.d.ts +43 -0
  28. package/dist/_vendor/sdk-runtime/sampling/index.js +70 -0
  29. package/dist/_vendor/telemetry-contract/sdk/public-contract.d.ts +175 -0
  30. package/dist/_vendor/telemetry-contract/sdk/public-contract.js +5 -0
  31. package/dist/autocapture.d.ts +14 -19
  32. package/dist/autocapture.js +77 -95
  33. package/dist/client.d.ts +12 -20
  34. package/dist/client.js +56 -72
  35. package/dist/config.d.ts +24 -0
  36. package/dist/config.js +26 -0
  37. package/dist/console-capture.d.ts +7 -0
  38. package/dist/console-capture.js +79 -0
  39. package/dist/errors.d.ts +2 -3
  40. package/dist/errors.js +8 -5
  41. package/dist/index.d.ts +5 -39
  42. package/dist/index.js +4 -82
  43. package/dist/next.d.ts +39 -0
  44. package/dist/next.js +67 -0
  45. package/dist/react.d.ts +0 -1
  46. package/dist/react.js +12 -10
  47. package/dist/replay-network.d.ts +20 -0
  48. package/dist/replay-network.js +193 -0
  49. package/dist/replay-privacy.d.ts +2 -3
  50. package/dist/replay-privacy.js +47 -17
  51. package/dist/replay-retry.d.ts +40 -0
  52. package/dist/replay-retry.js +193 -0
  53. package/dist/replay.d.ts +18 -6
  54. package/dist/replay.js +131 -71
  55. package/dist/runtime/client-singleton.d.ts +24 -0
  56. package/dist/runtime/client-singleton.js +66 -0
  57. package/dist/runtime/client.d.ts +21 -0
  58. package/dist/runtime/client.js +12 -0
  59. package/dist/runtime/replay.d.ts +12 -0
  60. package/dist/runtime/replay.js +15 -0
  61. package/dist/session.d.ts +0 -11
  62. package/dist/session.js +20 -21
  63. package/dist/telemetry.d.ts +1 -2
  64. package/dist/telemetry.js +13 -10
  65. package/dist/trace-context.d.ts +8 -0
  66. package/dist/trace-context.js +13 -0
  67. package/dist/transport.d.ts +11 -20
  68. package/dist/transport.js +86 -66
  69. package/dist/types.d.ts +38 -139
  70. package/dist/types.js +0 -7
  71. package/dist/vitals.d.ts +55 -3
  72. package/dist/vitals.js +115 -16
  73. package/package.json +11 -3
  74. package/dist/__tests__/client.test.d.ts +0 -2
  75. package/dist/__tests__/client.test.d.ts.map +0 -1
  76. package/dist/__tests__/client.test.js +0 -103
  77. package/dist/__tests__/errors.test.d.ts +0 -2
  78. package/dist/__tests__/errors.test.d.ts.map +0 -1
  79. package/dist/__tests__/errors.test.js +0 -80
  80. package/dist/__tests__/replay-privacy.test.d.ts +0 -2
  81. package/dist/__tests__/replay-privacy.test.d.ts.map +0 -1
  82. package/dist/__tests__/replay-privacy.test.js +0 -124
  83. package/dist/__tests__/replay-startup.test.d.ts +0 -2
  84. package/dist/__tests__/replay-startup.test.d.ts.map +0 -1
  85. package/dist/__tests__/replay-startup.test.js +0 -99
  86. package/dist/__tests__/replay.test.d.ts +0 -2
  87. package/dist/__tests__/replay.test.d.ts.map +0 -1
  88. package/dist/__tests__/replay.test.js +0 -217
  89. package/dist/__tests__/session.test.d.ts +0 -2
  90. package/dist/__tests__/session.test.d.ts.map +0 -1
  91. package/dist/__tests__/session.test.js +0 -46
  92. package/dist/__tests__/transport.test.d.ts +0 -2
  93. package/dist/__tests__/transport.test.d.ts.map +0 -1
  94. package/dist/__tests__/transport.test.js +0 -101
  95. package/dist/__tests__/types.test.d.ts +0 -2
  96. package/dist/__tests__/types.test.d.ts.map +0 -1
  97. package/dist/__tests__/types.test.js +0 -139
  98. package/dist/autocapture.d.ts.map +0 -1
  99. package/dist/client.d.ts.map +0 -1
  100. package/dist/errors.d.ts.map +0 -1
  101. package/dist/index.d.ts.map +0 -1
  102. package/dist/react.d.ts.map +0 -1
  103. package/dist/replay-privacy.d.ts.map +0 -1
  104. package/dist/replay.d.ts.map +0 -1
  105. package/dist/session.d.ts.map +0 -1
  106. package/dist/telemetry.d.ts.map +0 -1
  107. package/dist/transport.d.ts.map +0 -1
  108. package/dist/types.d.ts.map +0 -1
  109. package/dist/vitals.d.ts.map +0 -1
@@ -0,0 +1,175 @@
1
+ /**
2
+ * Customer-facing telemetry contract shared by the published JavaScript SDKs.
3
+ * This module intentionally contains only the documented ingestion shapes.
4
+ */
5
+ export type JsonPrimitive = boolean | null | number | string;
6
+ export interface JsonObject {
7
+ [key: string]: JsonValue;
8
+ }
9
+ export type JsonValue = JsonPrimitive | JsonValue[] | JsonObject;
10
+ export type Level = "fatal" | "error" | "warning" | "info" | "debug";
11
+ export interface StackFrame {
12
+ filename?: string;
13
+ function?: string;
14
+ lineno?: number;
15
+ colno?: number;
16
+ in_app?: boolean;
17
+ context_line?: string;
18
+ pre_context?: string[];
19
+ post_context?: string[];
20
+ }
21
+ export interface UserContext {
22
+ id?: string;
23
+ email?: string;
24
+ username?: string;
25
+ ip_address?: string;
26
+ }
27
+ export interface RequestContext {
28
+ url?: string;
29
+ method?: string;
30
+ headers?: Record<string, string>;
31
+ }
32
+ export interface Breadcrumb {
33
+ timestamp?: string;
34
+ category?: string;
35
+ message?: string;
36
+ level?: string;
37
+ data?: JsonObject;
38
+ }
39
+ /** Event payload accepted by the documented ingestion endpoint. */
40
+ export interface IngestEvent {
41
+ message: string;
42
+ type?: string;
43
+ stack?: string;
44
+ frames?: StackFrame[];
45
+ level?: Level;
46
+ tags?: Record<string, string>;
47
+ user?: UserContext;
48
+ request?: RequestContext;
49
+ sdk?: {
50
+ name: string;
51
+ version: string;
52
+ };
53
+ timestamp?: string;
54
+ release?: string;
55
+ environment?: string;
56
+ breadcrumbs?: Breadcrumb[];
57
+ extra?: Record<string, JsonValue>;
58
+ session_id?: string;
59
+ kind?: TelemetryKind;
60
+ event_name?: string;
61
+ distinct_id?: string;
62
+ visitor?: VisitorContext;
63
+ analytics?: AnalyticsContext;
64
+ page?: PageContext;
65
+ session?: SessionContext;
66
+ trace?: TraceContext;
67
+ tool_call?: ToolCallContext;
68
+ llm?: LlmContext;
69
+ attributes?: JsonObject;
70
+ measurements?: TelemetryMeasurement[];
71
+ resource_attributes?: Record<string, string>;
72
+ }
73
+ export interface IngestBatchPayload {
74
+ events: IngestEvent[];
75
+ }
76
+ export type IngestEventBatch = [IngestEvent, ...IngestEvent[]];
77
+ export interface IngestBatchEnvelope {
78
+ events: IngestEventBatch;
79
+ }
80
+ export type IngestJsonBatchPayload = IngestEventBatch | IngestBatchEnvelope;
81
+ export type IngestJsonPayload = IngestEvent | IngestJsonBatchPayload;
82
+ /** An encoded newline-delimited JSON request body. */
83
+ export type IngestNdjsonPayload = string;
84
+ export type IngestRequestPayload = IngestJsonPayload | IngestNdjsonPayload;
85
+ export type TelemetryKind = "error" | "log" | "analytics" | "identify" | "page" | "screen" | "visitor" | "agent_session" | "agent_span" | "tool_call" | "llm_generation" | "agent_score";
86
+ export interface VisitorContext {
87
+ visitor_id?: string;
88
+ anonymous_id?: string;
89
+ account_id?: string;
90
+ }
91
+ export interface AnalyticsContext {
92
+ event?: string;
93
+ category?: string;
94
+ funnel?: string;
95
+ step?: string;
96
+ properties?: JsonObject;
97
+ }
98
+ export interface PageContext {
99
+ name?: string;
100
+ path?: string;
101
+ title?: string;
102
+ referrer?: string;
103
+ search?: string;
104
+ screen_class?: string;
105
+ }
106
+ export interface SessionContext {
107
+ session_type?: string;
108
+ agent_id?: string;
109
+ run_id?: string;
110
+ workflow_id?: string;
111
+ step_id?: string;
112
+ status?: string;
113
+ duration_ms?: number;
114
+ }
115
+ export interface TraceContext {
116
+ trace_id?: string;
117
+ span_id?: string;
118
+ parent_span_id?: string;
119
+ span_name?: string;
120
+ span_kind?: string;
121
+ status?: string;
122
+ duration_ms?: number;
123
+ }
124
+ export interface ToolCallContext {
125
+ name?: string;
126
+ input?: JsonObject;
127
+ output?: JsonObject;
128
+ status?: string;
129
+ duration_ms?: number;
130
+ }
131
+ export interface LlmContext {
132
+ provider?: string;
133
+ model?: string;
134
+ prompt_tokens?: number;
135
+ completion_tokens?: number;
136
+ total_tokens?: number;
137
+ cached_input_tokens?: number;
138
+ cost_usd?: number;
139
+ latency_ms?: number;
140
+ status?: string;
141
+ input?: JsonObject;
142
+ output?: JsonObject;
143
+ }
144
+ export interface TelemetryMeasurement {
145
+ name: string;
146
+ value: number;
147
+ unit?: string;
148
+ }
149
+ /** Outcome-aware SDK sampling. Errors and slow operations are kept by default. */
150
+ export interface TelemetrySamplingConfig {
151
+ successRate?: number;
152
+ errorRate?: number;
153
+ slowRate?: number;
154
+ slowThresholdMs?: number;
155
+ alwaysSampleUserIds?: string[];
156
+ alwaysSampleReleases?: string[];
157
+ }
158
+ export interface IngestResponse {
159
+ id: string;
160
+ status: string;
161
+ accepted?: number;
162
+ }
163
+ export interface SdkConfig {
164
+ apiKey: string;
165
+ projectId: string;
166
+ endpoint?: string;
167
+ environment?: string;
168
+ release?: string;
169
+ debug?: boolean;
170
+ sampling?: TelemetrySamplingConfig;
171
+ beforeSend?: (event: IngestEvent) => IngestEvent | null;
172
+ maxBreadcrumbs?: number;
173
+ resourceAttributes?: Record<string, string>;
174
+ autoFlushIntervalMs?: number;
175
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Customer-facing telemetry contract shared by the published JavaScript SDKs.
3
+ * This module intentionally contains only the documented ingestion shapes.
4
+ */
5
+ export {};
@@ -1,21 +1,16 @@
1
1
  /**
2
- * Auto-capture breadcrumbs for navigation, clicks, and fetch errors.
3
- *
4
- * Breadcrumbs are lightweight events that provide context about what the
5
- * user was doing before an error occurred. They are attached to error
6
- * events to help with debugging and AI triage.
7
- *
8
- * Categories:
9
- * - "navigation" — route changes (pushState, replaceState, popstate)
10
- * - "ui.click" — user clicks on elements
11
- * - "fetch" — failed fetch requests (4xx/5xx)
12
- * - "console" — console.error / console.warn calls
2
+ * Auto-capture breadcrumbs. Categories emitted:
3
+ * - "navigation" — pushState/replaceState/popstate
4
+ * - "ui.click" — clicks on elements
5
+ * - "fetch" — 4xx/5xx fetch responses
6
+ * - "console" — console.error / console.warn calls
13
7
  */
14
- import type { Breadcrumb } from "./types";
15
- export type BreadcrumbCallback = (crumb: Omit<Breadcrumb, "timestamp">) => void;
16
- /**
17
- * Install all auto-capture hooks.
18
- * Returns a cleanup function to remove all hooks and restore originals.
19
- */
20
- export declare function installAutocapture(onBreadcrumb: BreadcrumbCallback): () => void;
21
- //# sourceMappingURL=autocapture.d.ts.map
8
+ import { type BreadcrumbCallback } from "./console-capture.js";
9
+ import type { BrowserErrorEvent } from "./types.js";
10
+ export type { BreadcrumbCallback } from "./console-capture.js";
11
+ export interface AutocaptureOptions {
12
+ captureBreadcrumbs?: boolean;
13
+ onConsoleError?: (event: BrowserErrorEvent) => void;
14
+ }
15
+ /** Installs all hooks. Returned function removes them and restores originals. */
16
+ export declare function installAutocapture(onBreadcrumb: BreadcrumbCallback, options?: AutocaptureOptions): () => void;
@@ -1,26 +1,28 @@
1
1
  /**
2
- * Auto-capture breadcrumbs for navigation, clicks, and fetch errors.
3
- *
4
- * Breadcrumbs are lightweight events that provide context about what the
5
- * user was doing before an error occurred. They are attached to error
6
- * events to help with debugging and AI triage.
7
- *
8
- * Categories:
9
- * - "navigation" — route changes (pushState, replaceState, popstate)
10
- * - "ui.click" — user clicks on elements
11
- * - "fetch" — failed fetch requests (4xx/5xx)
12
- * - "console" — console.error / console.warn calls
2
+ * Auto-capture breadcrumbs. Categories emitted:
3
+ * - "navigation" — pushState/replaceState/popstate
4
+ * - "ui.click" — clicks on elements
5
+ * - "fetch" — 4xx/5xx fetch responses
6
+ * - "console" — console.error / console.warn calls
13
7
  */
14
- /**
15
- * Install all auto-capture hooks.
16
- * Returns a cleanup function to remove all hooks and restore originals.
17
- */
18
- export function installAutocapture(onBreadcrumb) {
8
+ import { attemptAsync } from "./_vendor/result-runtime/attempt.js";
9
+ import { readRuntimeProperty, readRuntimeString } from "./_vendor/sdk-runtime/runtime/public-sdk-runtime.js";
10
+ import { captureConsole } from "./console-capture.js";
11
+ /** Installs all hooks. Returned function removes them and restores originals. */
12
+ export function installAutocapture(onBreadcrumb, options = {}) {
19
13
  const cleanups = [];
20
- cleanups.push(captureNavigation(onBreadcrumb));
21
- cleanups.push(captureClicks(onBreadcrumb));
22
- cleanups.push(captureFetch(onBreadcrumb));
23
- cleanups.push(captureConsole(onBreadcrumb));
14
+ const captureBreadcrumbs = options.captureBreadcrumbs ?? true;
15
+ if (captureBreadcrumbs) {
16
+ cleanups.push(captureNavigation(onBreadcrumb));
17
+ cleanups.push(captureClicks(onBreadcrumb));
18
+ cleanups.push(captureFetch(onBreadcrumb));
19
+ }
20
+ if (captureBreadcrumbs || options.onConsoleError) {
21
+ cleanups.push(captureConsole(onBreadcrumb, {
22
+ captureBreadcrumbs,
23
+ onConsoleError: options.onConsoleError,
24
+ }));
25
+ }
24
26
  return () => {
25
27
  for (const cleanup of cleanups) {
26
28
  cleanup();
@@ -43,13 +45,13 @@ function captureNavigation(onBreadcrumb) {
43
45
  };
44
46
  // Patch history.pushState
45
47
  const origPushState = history.pushState.bind(history);
46
- history.pushState = function (...args) {
48
+ history.pushState = (...args) => {
47
49
  origPushState(...args);
48
50
  emitNavCrumb();
49
51
  };
50
52
  // Patch history.replaceState
51
53
  const origReplaceState = history.replaceState.bind(history);
52
- history.replaceState = function (...args) {
54
+ history.replaceState = (...args) => {
53
55
  origReplaceState(...args);
54
56
  emitNavCrumb();
55
57
  };
@@ -65,20 +67,21 @@ function captureNavigation(onBreadcrumb) {
65
67
  // ─── Clicks ─────────────────────────────────────────────────────────────
66
68
  function captureClicks(onBreadcrumb) {
67
69
  const handler = (event) => {
68
- const target = event.target;
70
+ const target = readClickTarget(event.target);
69
71
  if (!target)
70
72
  return;
71
73
  const descriptor = describeElement(target);
72
74
  if (!descriptor)
73
75
  return;
76
+ const data = { tag: target.tagName.toLowerCase() };
77
+ if (target.id)
78
+ data.id = target.id;
79
+ if (target.className)
80
+ data.className = target.className;
74
81
  onBreadcrumb({
75
82
  category: "ui.click",
76
83
  message: descriptor,
77
- data: {
78
- tag: target.tagName?.toLowerCase(),
79
- id: target.id || undefined,
80
- className: target.className || undefined,
81
- },
84
+ data,
82
85
  });
83
86
  };
84
87
  // Use capture phase to catch clicks even if stopPropagation is called
@@ -87,27 +90,35 @@ function captureClicks(onBreadcrumb) {
87
90
  document.removeEventListener("click", handler, true);
88
91
  };
89
92
  }
93
+ function readClickTarget(target) {
94
+ const tagName = readRuntimeString(readRuntimeProperty(target, "tagName"));
95
+ if (!tagName)
96
+ return null;
97
+ return {
98
+ className: readRuntimeString(readRuntimeProperty(target, "className")) ?? "",
99
+ id: readRuntimeString(readRuntimeProperty(target, "id")) ?? "",
100
+ tagName,
101
+ textContent: readRuntimeString(readRuntimeProperty(target, "textContent")) ?? "",
102
+ };
103
+ }
90
104
  /**
91
105
  * Build a human-readable descriptor for a DOM element.
92
106
  * e.g. "button#submit-btn.primary" or "a.nav-link"
93
107
  */
94
108
  function describeElement(el) {
95
- const tag = el.tagName?.toLowerCase();
96
- if (!tag)
97
- return null;
109
+ const tag = el.tagName.toLowerCase();
98
110
  let desc = tag;
99
- const htmlEl = el;
100
- if (htmlEl.id) {
101
- desc += `#${htmlEl.id}`;
111
+ if (el.id) {
112
+ desc += `#${el.id}`;
102
113
  }
103
- if (htmlEl.className && typeof htmlEl.className === "string") {
104
- const classes = htmlEl.className.trim().split(/\s+/).slice(0, 2).join(".");
114
+ if (el.className) {
115
+ const classes = el.className.trim().split(/\s+/).slice(0, 2).join(".");
105
116
  if (classes) {
106
117
  desc += `.${classes}`;
107
118
  }
108
119
  }
109
120
  // Add text content for buttons/links (truncated)
110
- const textContent = htmlEl.textContent?.trim();
121
+ const textContent = el.textContent?.trim();
111
122
  if (textContent && (tag === "button" || tag === "a")) {
112
123
  const truncated = textContent.length > 30 ? `${textContent.slice(0, 30)}...` : textContent;
113
124
  desc += `[${truncated}]`;
@@ -116,76 +127,47 @@ function describeElement(el) {
116
127
  }
117
128
  // ─── Fetch ──────────────────────────────────────────────────────────────
118
129
  function captureFetch(onBreadcrumb) {
119
- if (typeof window === "undefined" || !window.fetch)
130
+ if (!globalThis.window?.fetch)
120
131
  return () => { };
121
132
  const origFetch = window.fetch.bind(window);
122
- window.fetch = async function (input, init) {
133
+ window.fetch = async (input, init) => {
123
134
  const method = init?.method?.toUpperCase() || "GET";
124
- const url = typeof input === "string"
125
- ? input
126
- : input instanceof URL
127
- ? input.href
128
- : input instanceof Request
129
- ? input.url
130
- : String(input);
131
- try {
132
- const response = await origFetch(input, init);
133
- // Only breadcrumb on error responses (4xx/5xx)
134
- if (response.status >= 400) {
135
+ const url = input instanceof URL ? input.href : input instanceof Request ? input.url : String(input);
136
+ return attemptAsync({
137
+ try: async () => {
138
+ const response = await origFetch(input, init);
139
+ // Only breadcrumb on error responses (4xx/5xx)
140
+ if (response.status >= 400) {
141
+ onBreadcrumb({
142
+ category: "fetch",
143
+ message: `${method} ${url} [${response.status}]`,
144
+ level: response.status >= 500 ? "error" : "warning",
145
+ data: {
146
+ method,
147
+ url,
148
+ status: response.status,
149
+ },
150
+ });
151
+ }
152
+ return response;
153
+ },
154
+ catch: ({ cause, error }) => {
155
+ // Network error
135
156
  onBreadcrumb({
136
157
  category: "fetch",
137
- message: `${method} ${url} [${response.status}]`,
138
- level: response.status >= 500 ? "error" : "warning",
158
+ message: `${method} ${url} [network error]`,
159
+ level: "error",
139
160
  data: {
140
161
  method,
141
162
  url,
142
- status: response.status,
163
+ error: error.message,
143
164
  },
144
165
  });
145
- }
146
- return response;
147
- }
148
- catch (error) {
149
- // Network error
150
- onBreadcrumb({
151
- category: "fetch",
152
- message: `${method} ${url} [network error]`,
153
- level: "error",
154
- data: {
155
- method,
156
- url,
157
- error: error instanceof Error ? error.message : String(error),
158
- },
159
- });
160
- throw error;
161
- }
162
- };
163
- return () => {
164
- window.fetch = origFetch;
165
- };
166
- }
167
- // ─── Console ────────────────────────────────────────────────────────────
168
- function captureConsole(onBreadcrumb) {
169
- const origError = console.error.bind(console);
170
- const origWarn = console.warn.bind(console);
171
- console.error = (...args) => {
172
- onBreadcrumb({
173
- category: "console",
174
- message: args.map(String).join(" ").slice(0, 200),
175
- level: "error",
176
- });
177
- origError(...args);
178
- };
179
- console.warn = (...args) => {
180
- onBreadcrumb({
181
- category: "console",
182
- message: args.map(String).join(" ").slice(0, 200),
183
- level: "warning",
166
+ throw cause;
167
+ },
184
168
  });
185
- origWarn(...args);
186
169
  };
187
170
  return () => {
188
- console.error = origError;
189
- console.warn = origWarn;
171
+ window.fetch = origFetch;
190
172
  };
191
173
  }
package/dist/client.d.ts CHANGED
@@ -1,15 +1,6 @@
1
- /**
2
- * BrowserClient the core SDK client for browser environments.
3
- *
4
- * Manages:
5
- * - Configuration with sensible defaults
6
- * - User context, tags, and breadcrumbs
7
- * - Web Vitals collection (via vitals.ts)
8
- * - Global error capture (via errors.ts)
9
- * - Auto-capture breadcrumbs (via autocapture.ts)
10
- * - Transport (via transport.ts)
11
- */
12
- import type { Breadcrumb, BrowserConfig, BrowserErrorEvent, JsonObject, Level, UserContext } from "./types";
1
+ import { type BrowserClientRuntime } from "./runtime/client.js";
2
+ import type { Breadcrumb, BrowserConfig, BrowserErrorEvent, JsonObject, Level, UserContext } from "./types.js";
3
+ import { type ExternalVitalInput } from "./vitals.js";
13
4
  export declare class BrowserClient {
14
5
  private config;
15
6
  private transport;
@@ -19,12 +10,13 @@ export declare class BrowserClient {
19
10
  private disabled;
20
11
  private cleanups;
21
12
  private replayRecorder;
22
- constructor(config: BrowserConfig);
13
+ private vitalsHandle;
14
+ constructor(config: BrowserConfig, runtime?: BrowserClientRuntime);
23
15
  setUser(user: UserContext | undefined): void;
24
16
  setTag(key: string, value: string): void;
25
17
  setTags(tags: Record<string, string>): void;
26
18
  addBreadcrumb(crumb: Omit<Breadcrumb, "timestamp">): void;
27
- captureError(error: Error, extra?: Record<string, unknown>): void;
19
+ captureError(error: Error, extra?: JsonObject): void;
28
20
  captureMessage(message: string, level?: Level): void;
29
21
  captureTelemetry(event: BrowserErrorEvent): void;
30
22
  track(eventName: string, properties?: JsonObject, context?: Partial<BrowserErrorEvent>): void;
@@ -34,13 +26,13 @@ export declare class BrowserClient {
34
26
  captureSpan(name: string, context?: Partial<BrowserErrorEvent>): void;
35
27
  captureToolCall(name: string, context?: Partial<BrowserErrorEvent>): void;
36
28
  captureGeneration(message: string, context?: Partial<BrowserErrorEvent>): void;
37
- /**
38
- * Flush remaining vitals and stop all timers.
39
- * Call this before unmounting a SPA or during cleanup.
40
- */
29
+ /** Record a web vital from an external collector (e.g. Next.js `useReportWebVitals`). */
30
+ recordWebVital(metric: ExternalVitalInput, route?: string): void;
31
+ /** Stop the SDK's native `web-vitals` collector to avoid double-counting. */
32
+ suppressNativeVitalsCollection(): void;
33
+ private vitalsConfig;
34
+ /** Flush vitals and stop timers. Call before unmounting a SPA. */
41
35
  close(): void;
42
- private shouldSample;
43
36
  /** Enrich an error event with current context and send it. */
44
37
  private sendErrorEvent;
45
38
  }
46
- //# sourceMappingURL=client.d.ts.map