@chrom-ar/collector 0.3.1 → 0.5.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/CHANGELOG.md +39 -0
- package/README.md +140 -22
- package/dist/chunk-42XODVHT.js +63 -0
- package/dist/collector.esm.js +7 -0
- package/dist/index.cjs +203 -42
- package/dist/index.d.cts +18 -121
- package/dist/index.d.ts +18 -121
- package/dist/index.js +187 -87
- package/dist/rum.cjs +645 -0
- package/dist/rum.d.cts +63 -0
- package/dist/rum.d.ts +63 -0
- package/dist/rum.esm.js +2 -0
- package/dist/rum.js +614 -0
- package/dist/types-ml-o_-mr.d.cts +183 -0
- package/dist/types-ml-o_-mr.d.ts +183 -0
- package/package.json +19 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0 (2026-11-23)
|
|
4
|
+
|
|
5
|
+
- Single-file builds for pages without a bundler: `dist/collector.esm.js`
|
|
6
|
+
and `dist/rum.esm.js` import nothing, so they work under any URL an
|
|
7
|
+
import map or a digested asset name gives them. Minified, with a
|
|
8
|
+
license line.
|
|
9
|
+
- A bare `init()` reads the DSN, environment and release from
|
|
10
|
+
`<meta name="collector-dsn">`, `collector-environment` and
|
|
11
|
+
`collector-release`, and the user from `collector-user` (a `setUser()`
|
|
12
|
+
call wins). Options passed to `init()` win over the tags.
|
|
13
|
+
- `rum()` without a `sampleRate` reads `collector-rum-sample-rate`, and
|
|
14
|
+
`<meta name="collector-route">` names the page load's page view
|
|
15
|
+
(`setRoute()` and the `route` option win over it).
|
|
16
|
+
- Turbo: on each `turbo:load`, the user and route tags are read again (a
|
|
17
|
+
missing user tag clears the user) and RUM counts the visit.
|
|
18
|
+
- **Can regroup issues:** on pages with an import map, frames from scoped
|
|
19
|
+
packages (`@scope/name`) and pins served from another origin are no
|
|
20
|
+
longer your code; with `<meta name="collector-in-app">`, only the
|
|
21
|
+
specifiers it lists are. Frames from `collector.esm.js` itself are never
|
|
22
|
+
your code. Errors whose grouping ran through those frames can open new
|
|
23
|
+
issues once.
|
|
24
|
+
- README: what a Content Security Policy needs (`connect-src` with the
|
|
25
|
+
DSN's origin, nothing else).
|
|
26
|
+
- README: Node servers use the new `@chrom-ar/collector-node`.
|
|
27
|
+
- README: source maps are uploaded with the `collector` CLI (now in Go);
|
|
28
|
+
the Vite plugin from `@chrom-ar/collector-cli` is gone. With Vite, set
|
|
29
|
+
the release with `define: { __COLLECTOR_RELEASE__ }`.
|
|
30
|
+
|
|
31
|
+
## 0.4.0 (2026-11-09)
|
|
32
|
+
|
|
33
|
+
- Page speed (RUM), opt-in and in its own import:
|
|
34
|
+
`import { rum } from "@chrom-ar/collector/rum"`, then
|
|
35
|
+
`init({ rum: rum({ sampleRate: 0.1 }) })`. It measures Web Vitals,
|
|
36
|
+
in-app navigation time, requests and slow resources, and sends page views
|
|
37
|
+
in batches (gzipped over 1 KB) when the tab is hidden. Apps without it
|
|
38
|
+
don't ship it.
|
|
39
|
+
- `setRoute(name)` names the current page for RUM.
|
|
40
|
+
- Errors from tabs RUM measures carry the visit's `session`.
|
|
41
|
+
|
|
3
42
|
## 0.3.1 (2026-11-07)
|
|
4
43
|
|
|
5
44
|
- `Collector.test()` sends one test error and resolves to `{ ok: true, id }`
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ which groups them into issues, emails you when one is new or comes back,
|
|
|
5
5
|
and shows you what broke and why.
|
|
6
6
|
|
|
7
7
|
Works with any framework (React, Vue, Svelte, Angular, plain pages), has
|
|
8
|
-
no dependencies and weighs about
|
|
8
|
+
no dependencies and weighs about 10 KB gzipped.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -41,6 +41,31 @@ Collector.init({ dsn: import.meta.env.VITE_COLLECTOR_DSN });
|
|
|
41
41
|
`environment` and `release` are optional. Issues are counted per
|
|
42
42
|
environment, and `release` tells you which deploy an error came from.
|
|
43
43
|
|
|
44
|
+
### Without a bundler
|
|
45
|
+
|
|
46
|
+
For pages that load modules straight from an import map (or a plain
|
|
47
|
+
`<script type="module">`), the package ships one file each that imports
|
|
48
|
+
nothing: `dist/collector.esm.js` and `dist/rum.esm.js`. Copy them into
|
|
49
|
+
your assets (they keep their license line), pin them, and give the
|
|
50
|
+
settings in meta tags, so a bare `init()` needs no build step:
|
|
51
|
+
|
|
52
|
+
```html
|
|
53
|
+
<meta name="collector-dsn" content="https://clt_…@app.clt.chrom.ar">
|
|
54
|
+
<meta name="collector-environment" content="production">
|
|
55
|
+
<meta name="collector-release" content="web@1.4.2">
|
|
56
|
+
<meta name="collector-user" content="u_42">
|
|
57
|
+
<script type="importmap">
|
|
58
|
+
{ "imports": { "@chrom-ar/collector": "/assets/collector.esm.js" } }
|
|
59
|
+
</script>
|
|
60
|
+
<script type="module">
|
|
61
|
+
import * as Collector from "@chrom-ar/collector";
|
|
62
|
+
Collector.init();
|
|
63
|
+
</script>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Options you pass to `init()` win over the tags. `collector-user` is
|
|
67
|
+
optional; a `setUser()` call wins over it, from then on.
|
|
68
|
+
|
|
44
69
|
### New domains
|
|
45
70
|
|
|
46
71
|
The first time events arrive from a new domain, Collector keeps them and
|
|
@@ -50,6 +75,33 @@ browser console:
|
|
|
50
75
|
|
|
51
76
|
> [collector] This site's domain (https://…) is blocked for this project in Collector (HTTP 403). Events won't be sent from this page.
|
|
52
77
|
|
|
78
|
+
### Content Security Policy
|
|
79
|
+
|
|
80
|
+
If your site sends a Content Security Policy, add your DSN's origin (its
|
|
81
|
+
scheme, host and port) to `connect-src`, next to the ones you already
|
|
82
|
+
allow:
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
Content-Security-Policy: connect-src 'self' https://app.clt.chrom.ar
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
That's all it needs, with or without RUM:
|
|
89
|
+
|
|
90
|
+
- Events, heartbeats, page views and `Collector.test()` go out with
|
|
91
|
+
`fetch` or `navigator.sendBeacon`, which `connect-src` covers.
|
|
92
|
+
- Nothing for `script-src` beyond your own scripts: the package is bundled
|
|
93
|
+
with your code (or served from your assets, without a bundler), and it
|
|
94
|
+
doesn't load scripts or use `eval` or `new Function`.
|
|
95
|
+
- RUM's performance measurements and its `sessionStorage` entry aren't
|
|
96
|
+
covered by CSP.
|
|
97
|
+
|
|
98
|
+
If `connect-src` is missing it, the browser blocks the requests and logs
|
|
99
|
+
its own CSP error in the console; nothing reaches Collector.
|
|
100
|
+
`Collector.test()` (see [Checking your setup](#checking-your-setup))
|
|
101
|
+
then answers "couldn't reach Collector (…). Check the DSN's host, your
|
|
102
|
+
network, and your Content-Security-Policy's connect-src." CSP violation reports
|
|
103
|
+
(`report-uri`, `report-to`) go wherever your policy says, not to Collector.
|
|
104
|
+
|
|
53
105
|
### Framework notes
|
|
54
106
|
|
|
55
107
|
- **Next.js, Nuxt, SvelteKit and other SSR frameworks:** importing the
|
|
@@ -65,6 +117,9 @@ browser console:
|
|
|
65
117
|
```
|
|
66
118
|
|
|
67
119
|
- **Vue:** add `app.config.errorHandler = (error) => Collector.captureException(error);`
|
|
120
|
+
- **Turbo:** on each `turbo:load`, the SDK reads the `collector-user` and
|
|
121
|
+
`collector-route` tags again (a missing `collector-user` clears the
|
|
122
|
+
user), and RUM counts the visit. Render the tags in your layout.
|
|
68
123
|
|
|
69
124
|
## Checking your setup
|
|
70
125
|
|
|
@@ -165,6 +220,57 @@ Other functions: `setTags(tags)`, `addBreadcrumb({ message, category?, level? })
|
|
|
165
220
|
`flush(timeoutMs?)` (waits until queued events are sent) and `close()`
|
|
166
221
|
(removes everything the SDK installed).
|
|
167
222
|
|
|
223
|
+
## Page speed (RUM)
|
|
224
|
+
|
|
225
|
+
Real User Monitoring shows how fast your pages are for the people using
|
|
226
|
+
them: Web Vitals per page, the slow requests pages make, and single
|
|
227
|
+
visits. It's off by default and ships as a separate import, so apps that
|
|
228
|
+
don't use it don't download it (about 4.5 KB gzipped):
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
import * as Collector from "@chrom-ar/collector";
|
|
232
|
+
import { rum } from "@chrom-ar/collector/rum";
|
|
233
|
+
|
|
234
|
+
Collector.init({ dsn: "…", rum: rum({ sampleRate: 0.1 }) });
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
- **Sampling:** `sampleRate` is the share of browser tabs measured,
|
|
238
|
+
decided once per tab. A measured tab sends all its page views. Without
|
|
239
|
+
it, `rum()` reads `<meta name="collector-rum-sample-rate" content="0.1">`;
|
|
240
|
+
with neither, nothing is measured.
|
|
241
|
+
- **What's measured:** for page loads, LCP, INP, CLS, TTFB and FCP; for
|
|
242
|
+
in-app navigations to a new path (pushState, LiveView; a new query
|
|
243
|
+
string alone, like a filter or a search box, stays the same page view),
|
|
244
|
+
INP, CLS and a navigation
|
|
245
|
+
time, from the click until the page's requests have finished and the DOM
|
|
246
|
+
has been quiet for half a second (at most 10 s). Plus the page's fetch
|
|
247
|
+
and XHR calls, and for slow pages the slowest resources it loaded.
|
|
248
|
+
- **When it sends:** in batches, when the tab is hidden or closed, and
|
|
249
|
+
every 10 page views or 5 minutes while it stays open. Batches over 1 KB
|
|
250
|
+
are gzipped. If Collector is down or slow, page views are dropped
|
|
251
|
+
quietly; nothing is retried.
|
|
252
|
+
- **Privacy:** no cookies, no user id, no query strings or fragments. A
|
|
253
|
+
random id for the tab's visit, and the tab's sampling decision, are kept
|
|
254
|
+
in `sessionStorage` (key `collector:rum`) and end with the tab. Errors
|
|
255
|
+
from a measured tab carry the visit's id, so an issue links to the visit.
|
|
256
|
+
Collector derives the country and browser and doesn't store the IP or
|
|
257
|
+
user agent. Whether you need consent for analytics is your call.
|
|
258
|
+
- **Routes:** Collector groups pages by guessing which path segments are
|
|
259
|
+
ids (`/orders/81` → `/orders/:id`). If your router knows the route, say
|
|
260
|
+
it after each navigation:
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
Collector.setRoute("/orders/:id");
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
or pass `route: (location) => …` to `rum()`, or render
|
|
267
|
+
`<meta name="collector-route" content="/orders/:id">`: it names the
|
|
268
|
+
page load, and with Turbo each visit. `setRoute()` wins over `route`,
|
|
269
|
+
and `route` over the tag. Apps that route in the `#hash` need one of
|
|
270
|
+
these: fragments are never sent, so every page would otherwise be `/`.
|
|
271
|
+
- **Editing or dropping page views:** `rum({ sampleRate, beforeSendPageview(pv) { … return pv; } })`;
|
|
272
|
+
return `null` to drop one.
|
|
273
|
+
|
|
168
274
|
## How errors are grouped
|
|
169
275
|
|
|
170
276
|
Collector groups events into issues by the error type and the functions
|
|
@@ -180,34 +286,45 @@ say so:
|
|
|
180
286
|
Collector.init({ dsn: "…", inAppUrls: ["https://cdn.example.com/app/"] });
|
|
181
287
|
```
|
|
182
288
|
|
|
289
|
+
On a page with an import map, a module pinned to a bare specifier is
|
|
290
|
+
judged by its specifier: scoped packages (`@scope/name`) and pins served
|
|
291
|
+
from another origin are dependencies, other pins stay your code. To say
|
|
292
|
+
exactly which pins are yours, list them (a trailing `/` covers every
|
|
293
|
+
specifier under it); every other pin is then a dependency:
|
|
294
|
+
|
|
295
|
+
```html
|
|
296
|
+
<meta name="collector-in-app" content="application controllers/">
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
`inAppUrls` wins over both. Frames from `collector.esm.js` itself are
|
|
300
|
+
never your code.
|
|
301
|
+
|
|
183
302
|
## Source maps
|
|
184
303
|
|
|
185
304
|
Upload your build's source maps and Collector shows your original files,
|
|
186
|
-
lines and function names, and groups errors by them.
|
|
187
|
-
|
|
305
|
+
lines and function names, and groups errors by them. Upload them with the
|
|
306
|
+
[`collector` CLI](https://github.com/chrom-ar/collector-cli) before you
|
|
307
|
+
deploy, with `COLLECTOR_UPLOAD_TOKEN` (from your project's settings) and
|
|
308
|
+
`COLLECTOR_DSN` set in your CI:
|
|
188
309
|
|
|
189
|
-
```
|
|
190
|
-
|
|
191
|
-
import collector from "@chrom-ar/collector-cli/vite";
|
|
192
|
-
|
|
193
|
-
export default defineConfig({ plugins: [collector()] });
|
|
310
|
+
```sh
|
|
311
|
+
collector upload ./dist --release "$GIT_SHA"
|
|
194
312
|
```
|
|
195
313
|
|
|
196
|
-
|
|
197
|
-
`
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
With another bundler, upload with the CLI before you deploy, and make the
|
|
202
|
-
release match:
|
|
314
|
+
Make the app report the same release: pass it to `init({ release })`, or
|
|
315
|
+
define the `__COLLECTOR_RELEASE__` constant at build time. With Vite, build
|
|
316
|
+
hidden source maps so the bundle doesn't point to them, and delete the maps
|
|
317
|
+
before you deploy (`collector upload --delete` does it):
|
|
203
318
|
|
|
204
|
-
```
|
|
205
|
-
|
|
319
|
+
```ts
|
|
320
|
+
// vite.config.ts
|
|
321
|
+
export default defineConfig({
|
|
322
|
+
build: { sourcemap: "hidden" },
|
|
323
|
+
define: { __COLLECTOR_RELEASE__: JSON.stringify(process.env.GIT_SHA) },
|
|
324
|
+
});
|
|
206
325
|
```
|
|
207
326
|
|
|
208
|
-
|
|
209
|
-
`__COLLECTOR_RELEASE__` constant at build time (e.g. webpack's
|
|
210
|
-
`new DefinePlugin({ __COLLECTOR_RELEASE__: JSON.stringify(sha) })`).
|
|
327
|
+
With webpack: `new DefinePlugin({ __COLLECTOR_RELEASE__: JSON.stringify(sha) })`.
|
|
211
328
|
|
|
212
329
|
## What it won't do (yet)
|
|
213
330
|
|
|
@@ -218,8 +335,9 @@ Pass the same value to `init({ release })`, or define the
|
|
|
218
335
|
(`Cart.checkout` in Chrome and `checkout` in Firefox both become
|
|
219
336
|
`checkout`), but Safari sometimes leaves frames out, so the same error
|
|
220
337
|
can occasionally group separately per browser.
|
|
221
|
-
- **Browsers only.** For servers, use a server SDK
|
|
222
|
-
([
|
|
338
|
+
- **Browsers only.** For servers, use a server SDK: Node
|
|
339
|
+
([`@chrom-ar/collector-node`](https://www.npmjs.com/package/@chrom-ar/collector-node),
|
|
340
|
+
for Express and Next.js) or [Elixir](https://hex.pm/packages/collector).
|
|
223
341
|
|
|
224
342
|
It never throws into your app, never blocks it, and keeps quiet in the
|
|
225
343
|
console unless something's misconfigured (or you set `debug: true`).
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// src/meta.ts
|
|
2
|
+
function readMeta(name) {
|
|
3
|
+
if (typeof document === "undefined") return void 0;
|
|
4
|
+
const content = document.querySelector(`meta[name="${name}"]`)?.content.trim();
|
|
5
|
+
return content === void 0 || content === "" ? void 0 : content;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// src/util.ts
|
|
9
|
+
function uuid4() {
|
|
10
|
+
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
11
|
+
const b = crypto.getRandomValues(new Uint8Array(16));
|
|
12
|
+
b[6] = (b[6] ?? 0) & 15 | 64;
|
|
13
|
+
b[8] = (b[8] ?? 0) & 63 | 128;
|
|
14
|
+
const h = Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
15
|
+
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
16
|
+
}
|
|
17
|
+
function truncate(s, max) {
|
|
18
|
+
if (s.length <= max) return s;
|
|
19
|
+
const last = s.charCodeAt(max - 1);
|
|
20
|
+
return s.slice(0, last >= 55296 && last <= 56319 ? max - 1 : max);
|
|
21
|
+
}
|
|
22
|
+
function safeStringify(value, max = 8192) {
|
|
23
|
+
return truncate(stringify(value), max);
|
|
24
|
+
}
|
|
25
|
+
function stringify(value) {
|
|
26
|
+
if (typeof value === "string") return value;
|
|
27
|
+
if (value === void 0 || typeof value === "function" || typeof value === "symbol" || typeof value === "bigint") {
|
|
28
|
+
return String(value);
|
|
29
|
+
}
|
|
30
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
31
|
+
try {
|
|
32
|
+
return JSON.stringify(value, (_key, v) => {
|
|
33
|
+
if (typeof v === "bigint") return v.toString();
|
|
34
|
+
if (typeof v === "object" && v !== null) {
|
|
35
|
+
if (seen.has(v)) return "[Circular]";
|
|
36
|
+
seen.add(v);
|
|
37
|
+
}
|
|
38
|
+
return v;
|
|
39
|
+
});
|
|
40
|
+
} catch {
|
|
41
|
+
try {
|
|
42
|
+
return String(value);
|
|
43
|
+
} catch {
|
|
44
|
+
return "[unserializable]";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function stripUrl(url) {
|
|
49
|
+
const i = url.search(/[?#]/);
|
|
50
|
+
return i === -1 ? url : url.slice(0, i);
|
|
51
|
+
}
|
|
52
|
+
var MAX_URL = 500;
|
|
53
|
+
function rumUrl(base, url) {
|
|
54
|
+
try {
|
|
55
|
+
const parsed = new URL(url, base);
|
|
56
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return void 0;
|
|
57
|
+
return (parsed.origin + parsed.pathname).slice(0, MAX_URL);
|
|
58
|
+
} catch {
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export { readMeta, rumUrl, safeStringify, stripUrl, truncate, uuid4 };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/*! @chrom-ar/collector v0.5.0 | MIT */
|
|
2
|
+
function ee(){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();let t=crypto.getRandomValues(new Uint8Array(16));t[6]=(t[6]??0)&15|64,t[8]=(t[8]??0)&63|128;let e=Array.from(t,n=>n.toString(16).padStart(2,"0")).join("");return `${e.slice(0,8)}-${e.slice(8,12)}-${e.slice(12,16)}-${e.slice(16,20)}-${e.slice(20)}`}function b(t,e){if(t.length<=e)return t;let n=t.charCodeAt(e-1);return t.slice(0,n>=55296&&n<=56319?e-1:e)}function W(t,e=8192){return b(Ae(t),e)}function Ae(t){if(typeof t=="string")return t;if(t===void 0||typeof t=="function"||typeof t=="symbol"||typeof t=="bigint")return String(t);let e=new WeakSet;try{return JSON.stringify(t,(n,r)=>{if(typeof r=="bigint")return r.toString();if(typeof r=="object"&&r!==null){if(e.has(r))return "[Circular]";e.add(r);}return r})}catch{try{return String(t)}catch{return "[unserializable]"}}}function f(t){let e=t.search(/[?#]/);return e===-1?t:t.slice(0,e)}var Ne=500;function te(t,e){try{let n=new URL(e,t);return n.protocol!=="http:"&&n.protocol!=="https:"?void 0:(n.origin+n.pathname).slice(0,Ne)}catch{return}}var ne;function re(t){ne=f(t);}var oe=()=>ne;function ie(t){let e;try{e=new URL(t);}catch{return null}if(e.protocol!=="https:"&&e.protocol!=="http:"||e.username==="")return null;let n=e.origin+e.pathname.replace(/\/+$/,""),r=e.username;return {url:`${n}/api/events?key=${r}`,heartbeatUrl:`${n}/api/heartbeats?key=${r}`,pageviewsUrl:`${n}/api/pageviews?key=${r}`,base:n,key:r}}var Me=250,Ue=/^\s*at (?:(.+?) \()?(.+?):(\d+):(\d+)\)?$/,Ie=/^(.*?)@(.*):(\d+):(\d+)$/,$e=/\((\S+?):(\d+):(\d+)\)/,Fe=/^(.*?) line (\d+) > (?:eval|Function)/,Be=new Set(["global code","module code","eval code"]);function se(t){let e=[];for(let n of t.split(`
|
|
3
|
+
`)){let r=Pe(n)??De(n);r&&e.push(r);}return e}function Pe(t){let e=Ue.exec(t);if(e?.[2]===void 0)return;let n=e[2],r=Number(e[3]),o=Number(e[4]);if(n.startsWith("eval at ")){let i=$e.exec(n);if(i?.[1]===void 0)return;n=i[1],r=Number(i[2]),o=Number(i[3]);}return {function:K(e[1]),url:n,line:r,column:o}}function De(t){let e=Ie.exec(t);if(e?.[2]===void 0||e[2]==="")return;let n=e[1],r=/^([^*]*)\*(.*)$/.exec(n??"");if(r){if(r[1]!=="async")return;n=r[2];}let o=Fe.exec(e[2]);return o?.[1]!==void 0&&o[1]!==""?{function:K(n),url:o[1],line:Number(o[2]),column:void 0}:{function:K(n),url:e[2],line:Number(e[3]),column:Number(e[4])}}function K(t){if(t===void 0||t===""||Be.has(t))return;let e=t.replace(/^async\*/,"").replace(/^(?:async|new) /,"").replace(/ \[as [^\]]*\]$/,"").replace(/[/<]+$/,""),n=e.slice(Math.max(e.lastIndexOf("."),e.lastIndexOf("/"))+1);return n!==""&&n!=="<anonymous>"?n:void 0}function X(t){return /^(?:chrome|moz|safari|safari-web)-extension:\/\//.test(t)}var je=[/\/node_modules\//,/\/\.vite\/deps\//,/\/vendors?(?:\/|[-.~][^/]*$)/,/chunk-vendors/,/vendors~/,/\/@vite\//,/\/@react-refresh/,/\/_next\/static\/chunks\/(?:framework|main|webpack)[-.]/],qe=/[-.~]([A-Za-z0-9_]{8,}|[A-Za-z0-9_-]{8})(?=\.)/g;function He(t){return /\d/.test(t)?true:t.length!==8?false:/[_-]/.test(t)||/[A-Z]/.test(t)&&/[a-z]/.test(t)&&!/[a-z]{3}/.test(t)}function We(t){let e=f(t),n=e.lastIndexOf("/")+1,r=e.slice(n).replace(qe,(o,i)=>He(i)?"":o);return e.slice(0,n)+r}function ae(t,e){let n=[];for(let r of t)if(r.function?.startsWith("__collector")!==true){if(n.length===Me)break;n.push(Ke(r,e));}return n}function Ke(t,{origin:e,inAppUrls:n,classify:r,sdkFile:o}){let i;try{i=new URL(t.url,e);}catch{i=void 0;}let s=t.url.startsWith("webpack-internal://"),u=i?.origin===e||s,c=f(t.url);i&&!s&&(c=u?i.pathname:f(i.href));let a=d();function d(){if(o!==void 0&&i!==void 0&&f(i.href)===o)return false;if(n)return n.some(h=>typeof h=="string"?t.url.includes(h):h.test(t.url));let g=i===void 0?void 0:r?.(i.href);return g!==void 0?g==="app":u&&!X(t.url)&&!je.some(h=>h.test(c))}let l={module:We(c),function:t.function??"?",file:c,in_app:a};return t.line!==void 0&&(l.line=t.line),t.column!==void 0&&(l.column=t.column),l}var G=8192,Xe=new Set(["fatal","error","warning","info"]),Ge={debug:"info",log:"info",warn:"warning",critical:"fatal"};function Ve(t){return typeof t!="string"?"error":Xe.has(t)?t:Ge[t]??"error"}var x="@chrom-ar/collector";function Qe(t){if(t instanceof Error)return true;if(typeof t!="object"||t===null)return false;let e=t;return typeof e.message=="string"&&(typeof e.name=="string"||typeof e.stack=="string")}function ze(t){if(typeof t.name=="string"&&t.name!=="")return t.name;let e=t.constructor?.name;return typeof e=="string"&&e!==""&&e!=="Object"?e:"Error"}function V(t,e,n,r="manual"){let o=ce(e,n);if(Qe(t)){let i=typeof t.stack=="string"?ae(se(t.stack),{origin:e.origin,inAppUrls:e.options.inAppUrls,classify:e.classify,sdkFile:oe()}):[];o.exception={type:ze(t),message:b(String(t.message),G)},i.length>0&&(o.exception.frames=i);}else o.exception={type:r==="onunhandledrejection"?"UnhandledRejection":"NonError",message:W(t,G)};return o}function ue(t,e,n){let r=ce(e,n);return r.message=W(t,G),r}function Je(){return typeof __COLLECTOR_RELEASE__=="string"?__COLLECTOR_RELEASE__:void 0}function k(t){let e=t.release??Je();return e===""?void 0:e}function T(t){return typeof t.environment=="string"&&t.environment!==""?t.environment:void 0}function ce({options:t,scope:e,href:n,userAgent:r,session:o},i={}){let s={v:1,uuid:ee(),timestamp:new Date().toISOString(),platform:"javascript",level:Ve(i.level),request:{url:t.stripQuery===false?n:f(n),headers:{"user-agent":r}},sdk:{name:x,version:"0.5.0"}},u=T(t);u!==void 0&&(s.environment=u);let c=k(t);c!==void 0&&(s.release=c),o!==void 0&&(s.session=o),i.fingerprint&&i.fingerprint.length>0&&(s.fingerprint=i.fingerprint.map(String));let a=i.user?{id:String(i.user.id)}:e.user;a&&(s.user=a);let d={...e.tags,...i.tags};Object.keys(d).length>0&&(s.tags=d);let l=e.getBreadcrumbs();return l.length>0&&(s.breadcrumbs=l),s}var de=["ResizeObserver loop limit exceeded","ResizeObserver loop completed with undelivered notifications",/^(?:Error: )?Script error\.?$/];function le(t){let{exception:e}=t;return e?e.message!==void 0&&e.message!==""?`${e.type}: ${e.message}`:e.type:t.message??""}function fe(t,e){let n=t.exception?.frames;if(n!==void 0&&n.length>0&&n.every(o=>X(o.file)))return true;let r=le(t);return e.some(o=>typeof o=="string"?r.includes(o):o.test(r))}var A=class{constructor(e=1e3){this.windowMs=e;this.lastAt=0;}isDuplicate(e,n){let r=(e.exception?.frames??[]).slice(0,5).map(s=>`${s.file}:${String(s.line)}:${String(s.column)}`),o=`${le(e)}
|
|
4
|
+
${r.join(`
|
|
5
|
+
`)}`,i=o===this.last&&n-this.lastAt<=this.windowMs;return this.last=o,this.lastAt=n,i}},N=class{constructor(e=30,n=1e4){this.max=e;this.windowMs=n;this.times=[];}take(e){return this.times=this.times.filter(n=>e-n<this.windowMs),this.times.length>=this.max?false:(this.times.push(e),true)}};function pe(t,e,n){let r=i=>{try{if(typeof i.target?.nodeType=="number")return;let s=i;e(s.error??Ze(s),"onerror");}catch{}},o=i=>{try{e(i.reason,"onunhandledrejection");}catch{}};return n.onerror&&t.addEventListener("error",r),n.onunhandledrejection&&t.addEventListener("unhandledrejection",o),()=>{t.removeEventListener("error",r),t.removeEventListener("unhandledrejection",o);}}var Ye=/^(?:Uncaught |uncaught exception: )?(null|undefined)$/;function Ze(t){let e=Ye.exec(t.message),n=new Error(e?.[1]??(t.message!==""?t.message:"Unknown error"));return e&&(n.name="NonError"),n.stack=typeof t.filename=="string"&&t.filename!==""?`${n.name}: ${n.message}
|
|
6
|
+
at ? (${t.filename}:${String(t.lineno)}:${String(t.colno)})`:"",n}function E(t){if(typeof document>"u")return;let e=document.querySelector(`meta[name="${t}"]`)?.content.trim();return e===void 0||e===""?void 0:e}var et=t=>!/^(?:\.{0,2}\/|[a-z][a-z\d+.-]*:)/i.test(t);function tt(t){let n=t.querySelector('script[type="importmap"]')?.textContent;if(n===void 0||n==="")return;let r;try{r=JSON.parse(n);}catch{return}let o=typeof r=="object"&&r!==null&&"imports"in r?r.imports:void 0;if(typeof o!="object"||o===null)return;let i=[];for(let[s,u]of Object.entries(o))if(!(typeof u!="string"||!et(s)))try{i.push({specifier:s,url:f(new URL(u,t.baseURI).href),prefix:s.endsWith("/")});}catch{}return i.sort((s,u)=>s.prefix===u.prefix?u.url.length-s.url.length:Number(s.prefix)-Number(u.prefix))}var nt=(t,e)=>t.some(n=>n===e||n.endsWith("/")&&e.startsWith(n));function me(t,e){let n=tt(t);if(!n||n.length===0)return;let r=E("collector-in-app")?.split(/[\s,]+/).filter(o=>o!=="");return o=>{let i=f(o),s=n.find(c=>c.prefix?i.startsWith(c.url):i===c.url);if(!s)return;let u=s.prefix?s.specifier+i.slice(s.url.length):s.specifier;return r?nt(r,u)?"app":"dependency":u.startsWith("@")||!s.url.startsWith(`${e}/`)?"dependency":void 0}}var ge=5e3,rt="collector:heartbeat:",he=new Set;function ye(t){let e,n=()=>{it(t);},r=setTimeout(()=>{"requestIdleCallback"in globalThis?e=requestIdleCallback(n,{timeout:ge}):n();},ge);return ()=>{clearTimeout(r),e!==void 0&&cancelIdleCallback(e);}}function ot(t){try{return localStorage.getItem(t)}catch{return null}}async function it({url:t,key:e,fetch:n,options:r,logger:o}){let i=k(r),s=T(r),u=rt+e,c=JSON.stringify([new Date().toISOString().slice(0,10),i??"",s??""]);if(ot(u)===c||he.has(u+c))return;let a;try{let d=JSON.stringify({v:1,sdk:{name:x,version:"0.5.0"},environment:s,release:i});({status:a}=await n(t,{method:"POST",body:d,headers:{"Content-Type":"text/plain;charset=UTF-8"},keepalive:!0,credentials:"omit"}));}catch(d){o.debug("heartbeat not sent",d);return}if(!(a===429||a>=500))try{localStorage.setItem(u,c);}catch{he.add(u+c);}}var M=10,st=100;function U(t,e=false){if(typeof t=="string")return e?JSON.stringify(b(t,st)):t;if(t===null||typeof t!="object")return typeof t=="function"?`[Function ${t.name!==""?t.name:"anonymous"}]`:String(t);let n=t;if(t instanceof Error||typeof n.message=="string"&&typeof n.name=="string")return `${String(n.name)}: ${String(n.message)}`;if(typeof n.nodeType=="number")return typeof n.tagName=="string"?`<${n.tagName.toLowerCase()}>`:"[Node]";if(e)return Array.isArray(t)?`[Array(${String(t.length)})]`:"{\u2026}";if(Array.isArray(t))return `[${t.slice(0,M).map(o=>U(o,true)).join(", ")}${t.length>M?", \u2026":""}]`;try{let r=Object.keys(t);return `{${r.slice(0,M).map(i=>`${i}: ${U(t[i],!0)}`).join(", ")}${r.length>M?", \u2026":""}}`}catch{return "{\u2026}"}}var ve="__collector_original__";function w(t,e,n){let r=t[e];if(typeof r!="function"||r[ve]!==void 0)return ()=>true;let o=n(r);return Object.defineProperty(o,ve,{value:r}),t[e]=o,()=>t[e]!==o?false:(t[e]=r,true)}function m(t){try{t();}catch{}}function R(t,e,n){let r=e;try{let o=new URL(e,t.location.href);o.username="",o.password="",r=o.origin===t.location.origin?o.pathname+o.search+o.hash:o.href;}catch{}return n?f(r):r}function I(t,e,n,r){let o=t.onRequest?te(e.location.href,r):void 0;if(o===void 0)return ()=>{};let i=performance.now(),s=t.onRequestStart?.();return u=>{t.onRequest?.({method:n.toUpperCase(),url:o,status:u??0,start:i,end:performance.now()},s);}}function $(t,e){try{return new URL(e,t.location.href).href}catch{return e}}function F(t){return t===void 0||t>=500?"error":t>=400?"warning":"info"}function B(t,e,n){return `${t.toUpperCase()} ${e} \u2192 ${n===void 0?"failed":String(n)}`}var be={error:"error",warn:"warning",log:"info",info:"info"};function we(t,e,n){let r=t.console,o=Object.keys(be).map(i=>w(r,i,s=>function(...c){m(()=>{e({category:"console",level:be[i],message:b(c.map(a=>U(a)).join(" "),500)});}),s.apply(this,c);}));return ()=>o.map(i=>i()).every(Boolean)}var at=3;function ut(t){let e=[],n=t;for(;n&&e.length<at&&n.tagName!=="BODY"&&n.tagName!=="HTML";){let r=n.tagName.toLowerCase();n.id!==""&&(r+=`#${n.id}`);for(let o of Array.from(n.classList))r+=`.${o}`;e.unshift(r),n=n.parentElement;}return e.join(" > ")}function Ee(t,e,n){let r=o=>{m(()=>{let i=o.target;if(i?.nodeType!==1)return;let s=ut(i);s!==""&&e({category:"ui.click",level:"info",message:s});});};return t.document.addEventListener("click",r,true),()=>(t.document.removeEventListener("click",r,true),true)}function ct(t,e){let n=typeof Request<"u"&&t instanceof Request,r;return n?r=t.url:t instanceof URL?r=t.href:r=String(t),{method:e?.method??(n?t.method:"GET"),url:r}}function Se(t,e,n){return w(t,"fetch",r=>async function(i,s){let u=r.apply(this,arguments),c=a=>{};return m(()=>{let{method:a,url:d}=ct(i,s);if(n.skipUrl($(t,d)))return;let l=R(t,d,n.stripQuery),g=I(n,t,a,d);c=h=>{m(()=>{g(h),e({category:"fetch",level:F(h),message:B(a,l,h)});});};}),u.then(a=>(c(a.status),a),a=>{throw c(void 0),a})})}function Re(t,e,n){let r=()=>{let d=R(t,t.location.href,n.stripQuery),{hash:l}=t.location;return !n.stripQuery||!/^#!?\//.test(l)?d:`${d}#${f(l.slice(1))}`},o=r(),i=()=>{m(()=>{let d=r();d!==o&&(e({category:"navigation",level:"info",message:`${o} \u2192 ${d}`}),o=d);});},s=d=>w(t.history,d,l=>function(...h){l.apply(this,h),i(),u();}),u=()=>{m(()=>{n.onNavigate?.();});},c=()=>{i(),u();},a=[s("pushState"),s("replaceState")];return t.addEventListener("popstate",c),t.addEventListener("hashchange",i),()=>a.map(d=>d()).every(Boolean)?(t.removeEventListener("popstate",c),t.removeEventListener("hashchange",i),true):false}function xe(t,e,n){let r=t.XMLHttpRequest;if(!r)return ()=>true;let o=r.prototype,i=new WeakMap,s=w(o,"open",c=>function(...d){m(()=>{let[l,g]=d;i.set(this,{method:String(l),url:g instanceof URL?g.href:String(g)});}),c.apply(this,d);}),u=w(o,"send",c=>function(d){m(()=>{let l=i.get(this);if(!l||n.skipUrl($(t,l.url)))return;let g=R(t,l.url,n.stripQuery),h=I(n,t,l.method,l.url);this.addEventListener("loadend",()=>{m(()=>{let H=this.status!==0?this.status:void 0;h(H),e({category:"xhr",level:F(H),message:B(l.method,g,H)});});},{once:!0});}),c.call(this,d);});return ()=>[s(),u()].every(Boolean)}function ke(t){let e=new Set,{debug:n,info:r,warn:o}=console;return {debug(...i){t()&&n.call(console,"[collector]",...i);},warnOnce(i){e.has(i)||(e.add(i),o.call(console,`[collector] ${i}`));},info(i){r.call(console,`[collector] ${i}`);},warn(i){o.call(console,`[collector] ${i}`);}}}var dt=500,S=class{constructor(){this.tags={};this.breadcrumbs=[];}setUser(e){this.user=e?{id:String(e.id)}:void 0;}setTag(e,n){this.tags[e]=String(n);}setTags(e){for(let[n,r]of Object.entries(e))this.setTag(n,r);}addBreadcrumb(e,n){this.breadcrumbs.push({...e,timestamp:e.timestamp??new Date().toISOString(),message:b(String(e.message),dt)}),this.breadcrumbs.length>n&&this.breadcrumbs.splice(0,this.breadcrumbs.length-n);}getBreadcrumbs(){return this.breadcrumbs.map(e=>({...e}))}clear(){this.user=void 0,this.tags={},this.breadcrumbs=[];}};function _(t,e){let{onAnswer:n}=t;t.onAnswer=void 0,n?.(e);}var Q=1e3,lt=6e4,ft=8,pt=60,Te=6e4,z=1e6,mt=50,gt=new TextEncoder,C=t=>gt.encode(t).length,P=class{constructor(e){this.deps=e;this.disabled=false;this.queue=[];this.inFlight=false;this.paused=false;this.backoff=Q;this.inFlightKeepaliveBytes=0;this.idleWaiters=[];this.maxQueue=e.maxQueue??30;}send(e,n){if(!this.disabled){if(this.queue.length>=this.maxQueue){let r=this.queue.shift();r&&_(r,{error:new Error("dropped: too many events queued")}),this.deps.logger.debug("queue full, dropped the oldest event");}this.queue.push({event:e,attempts:0,...n?{onAnswer:n}:{}}),this.dispatch();}}async flush(e=2e3){return this.isIdle()?Promise.resolve(true):new Promise(n=>{let r=setTimeout(()=>{this.idleWaiters=this.idleWaiters.filter(i=>i!==o),n(false);},e),o=()=>{clearTimeout(r),n(true);};this.idleWaiters.push(o);})}sendQueuedNow(){if(this.disabled||this.paused)return;let e=Te-this.inFlightKeepaliveBytes;for(let{event:n}of this.queue.splice(0)){let r=_e(n);if(r===void 0)continue;let o=C(r),i=o<=e;i&&(e-=o);try{this.deps.fetch(this.deps.url,{method:"POST",body:r,headers:{"Content-Type":"text/plain;charset=UTF-8"},keepalive:i,credentials:"omit"}).catch(()=>{});}catch{}}this.notifyIfIdle();}isIdle(){return !this.inFlight&&(this.queue.length===0||this.disabled)}dispatch(){let e=this.inFlight||this.paused||this.disabled?void 0:this.queue.shift();if(!e){this.notifyIfIdle();return}let n=_e(e.event);if(n===void 0){this.deps.logger.debug("dropped an event that is over 1 MB or not JSON-encodable",e.event.uuid),_(e,{error:new Error("dropped: over 1 MB or not JSON-encodable")}),this.dispatch();return}this.inFlight=true;let r=C(n),o=r<=Te;this.inFlightKeepaliveBytes=o?r:0;let i;try{i=this.deps.fetch(this.deps.url,{method:"POST",body:n,headers:{"Content-Type":"text/plain;charset=UTF-8"},keepalive:o,credentials:"omit"});}catch(s){i=Promise.reject(s instanceof Error?s:new Error(String(s)));}i.then(s=>{this.handle(e,s);},s=>{this.retry(e,s);});}handle(e,n){this.inFlight=false,this.inFlightKeepaliveBytes=0;let{status:r}=n;if(_(e,{status:r}),r>=200&&r<300)this.backoff=Q;else if(r===429)this.backoff=Q,this.pause(ht(n.headers.get("Retry-After"))*1e3);else if(r===401||r===403)this.disable(r);else if(r>=500){this.retry(e,`HTTP ${String(r)}`);return}else {let{logger:o}=this.deps;n.text().then(i=>{o.debug(`Collector rejected an event (HTTP ${String(r)})`,e.event.uuid,i);},()=>{o.debug(`Collector rejected an event (HTTP ${String(r)})`,e.event.uuid);});}this.dispatch();}retry(e,n){_(e,{error:n}),this.inFlight=false,this.inFlightKeepaliveBytes=0,e.attempts+=1,e.attempts>=ft?this.deps.logger.debug(`gave up on an event after ${String(e.attempts)} tries`,n):(this.deps.logger.debug("sending failed, will retry",n),this.queue.unshift(e));let r=this.backoff;this.backoff=Math.min(this.backoff*2,lt),this.pause(r);}pause(e){this.paused=true,setTimeout(()=>{this.paused=false,this.dispatch();},e);}disable(e){this.disabled=true;for(let r of this.queue.splice(0))_(r,{error:new Error(`dropped: Collector rejected this DSN (HTTP ${String(e)})`)});this.deps.onDisable?.();let n=this.deps.origin??"unknown origin";this.deps.logger.warnOnce(e===401?"Collector rejected the key (HTTP 401): check the DSN on your project's setup page. Nothing more will be sent from this page.":`This site's domain (${n}) is blocked for this project in Collector (HTTP 403). Events won't be sent from this page. A project admin can unblock it in the project's settings.`);}notifyIfIdle(){if(!this.isIdle())return;let e=this.idleWaiters;this.idleWaiters=[];for(let n of e)n();}};function ht(t){let e=Number.parseInt(t??"",10);return e>=0?e:pt}function _e(t){try{return yt(t)}catch{return}}function yt(t){let e=JSON.stringify(t);if(C(e)<=z)return e;let n={...t};if(delete n.breadcrumbs,e=JSON.stringify(n),C(e)<=z||n.exception?.frames&&(n.exception={...n.exception,frames:n.exception.frames.slice(0,mt)},e=JSON.stringify(n),C(e)<=z))return e}var vt={console:we,dom:Ee,fetch:Se,xhr:xe,history:Re},bt=50,Ce=1e4;function wt(t){if("error"in t)return `couldn't reach Collector (${t.error instanceof Error?t.error.message:String(t.error)}). Check the DSN's host, your network, and your Content-Security-Policy's connect-src.`;let{status:e}=t;if(!(e>=200&&e<300))return e===401?"Collector rejected the key (HTTP 401). Check the DSN on your project's setup page.":e===403?"this site's domain is blocked for the project (HTTP 403). A project admin can unblock it in the project's settings.":e===429?"Collector asked to slow down (HTTP 429). Try again in a minute.":e>=500?`Collector had an error (HTTP ${String(e)}). The event will be retried.`:`Collector rejected the event (HTTP ${String(e)}).`}var v,D=new Map,Et={skipUrl:t=>v?.isOwnUrl(t)??false,get stripQuery(){return v?.options.stripQuery!==false},onRequestStart:()=>v?.rum?.requestStart(),onRequest:(t,e)=>{v?.rum?.request(t,e);},onNavigate:()=>{v?.rum?.navigate();}},St=new Set(["fetch","xhr","history"]),Oe=new Set,Rt=t=>e=>{v&&v.options.breadcrumbs?.[t]!==false&&v.addBreadcrumb(e);};function xt(t){return t.__collector_original__??t}var j=class{constructor(e,n,r=new S){this.options=e;this.win=n;this.scope=r;this.cleanups=[];this.deduper=new A;this.rateGuard=new N;this.closed=false;if(this.logger=ke(()=>e.debug===true),this.ignore=[...de,...e.ignoreErrors??[]],e.enabled===false){this.logger.debug("disabled (enabled: false): nothing will be sent"),this.inactive="the SDK is off (enabled: false).";return}if(typeof e.dsn!="string"||e.dsn===""){this.logger.debug("no DSN given: nothing will be sent"),this.inactive="no DSN given to init().";return}let o=ie(e.dsn);if(!o){this.logger.debug("invalid DSN: nothing will be sent",e.dsn),this.inactive="invalid DSN. Copy it from your project's setup page.";return}this.endpointBase=o.base;let i=xt(n.fetch).bind(n),{url:s}=o;this.transport=new P({url:s,fetch:i,logger:this.logger,origin:n.location.origin,onDisable:()=>Oe.add(s)}),Oe.has(s)?(this.transport.disabled=true,this.logger.debug("Collector already rejected this DSN on this page: nothing will be sent")):e.heartbeat!==false&&this.cleanups.push(ye({url:o.heartbeatUrl,key:o.key,fetch:i,options:e,logger:this.logger}));let u=e.autoCapture;if(u!==false&&this.cleanups.push(pe(n,(a,d)=>this.captureException(a,void 0,d),{onerror:u?.onerror!==false,onunhandledrejection:u?.onunhandledrejection!==false})),e.rum&&!this.transport.disabled)try{this.rum=e.rum.start({win:n,url:o.pageviewsUrl,fetch:i,logger:this.logger,options:e,sdk:{name:x,version:"0.5.0"},environment:T(e),release:k(e)});}catch(a){this.logger.debug("RUM didn't start",a);}v=this;for(let[a,d]of Object.entries(vt))if(!(!(e.breadcrumbs?.[a]!==false||this.rum!==void 0&&St.has(a))||D.has(a)))try{D.set(a,d(n,Rt(a),Et));}catch(g){this.logger.debug(`couldn't record ${a} breadcrumbs`,g);}let c=()=>{this.transport?.sendQueuedNow();};n.addEventListener("pagehide",c),this.cleanups.push(()=>{n.removeEventListener("pagehide",c);});}captureException(e,n,r="manual"){return this.capture(()=>V(e,this.env(),n,r))}captureMessage(e,n){let r=typeof n=="string"?{level:n}:n;return this.capture(()=>ue(e,this.env(),r))}async test(){let e=i=>(this.logger.warn(`Test event not sent: ${i}`),{ok:false,reason:i}),{transport:n}=this;if(this.closed)return Promise.resolve(e("the SDK was closed."));if(!n)return Promise.resolve(e(this.inactive??"the SDK isn't sending."));if(n.disabled)return Promise.resolve(e("Collector already rejected this DSN on this page (HTTP 401/403)."));let r;try{let i=new Error("Test event from Collector.test(). If you can see it in Collector, your setup works.");throw i.name="CollectorTest",i}catch(i){r=V(i,this.env(),{tags:{"collector.test":"true"},fingerprint:["collector.test"]});}let o=this.beforeSend(r)??r;return new Promise(i=>{let s=false,u=a=>{s||(s=true,clearTimeout(c),i(a));},c=setTimeout(()=>{u(e(`no answer from Collector within ${String(Ce/1e3)} s.`));},Ce);n.send(o,a=>{if(s)return;let d=wt(a);if(d!==void 0){u(e(d));return}this.logger.info(`Test event sent (${"status"in a?String(a.status):"?"}). Look for "CollectorTest" in your project: ${o.uuid}`),u({ok:true,id:o.uuid});});})}addBreadcrumb(e){this.scope.addBreadcrumb(e,this.options.maxBreadcrumbs??bt);}async flush(e){return this.transport?this.transport.flush(e):Promise.resolve(true)}setRoute(e){this.rum?.setRoute(e);}isOwnUrl(e){return this.endpointBase!==void 0&&e.startsWith(`${this.endpointBase}/`)}close(){this.closed=true;try{this.rum?.close();}catch(e){this.logger.debug("RUM didn't close cleanly",e);}if(v===this){v=void 0;for(let[e,n]of D)try{n()&&D.delete(e);}catch{}}for(let e of this.cleanups.splice(0).reverse())try{e();}catch(n){this.logger.debug("cleanup failed",n);}}env(){let{win:e}=this;return this.classify??(this.classify={fn:me(e.document,e.location.origin)}),{options:this.options,scope:this.scope,origin:e.location.origin,href:e.location.href,userAgent:e.navigator.userAgent,session:this.rum?.session,classify:this.classify.fn}}capture(e){let n=this.transport;if(!n||this.closed||n.disabled)return;let r=e();if(fe(r,this.ignore)){this.logger.debug("ignored",r.exception?.type??r.message);return}let o=Date.now();if(this.deduper.isDuplicate(r,o))return;let i=this.beforeSend(r);if(i){if(!this.rateGuard.take(o)){this.logger.debug("too many events, dropped one");return}return n.send(i),i.uuid}}beforeSend(e){let n=this.options.beforeSend;if(!n)return e;let r;try{r=n(e);}catch(o){return this.logger.debug("beforeSend threw; sending the event unchanged",o),e}if(r!==null){if((typeof r=="object"||typeof r=="function")&&"then"in r&&typeof r.then=="function"){this.logger.warnOnce("beforeSend returned a Promise, so the event was dropped. It must return the event (or null) right away, not async.");return}if(typeof r!="object"||Array.isArray(r)||!("uuid"in r)||typeof r.uuid!="string"){this.logger.debug("beforeSend returned neither an event nor null; dropped",r);return}return r}}};var Mn="0.5.0",p,O,Y=new S,Z=false,q;function L(){return p?.scope??Y}function y(t,e){try{return t()}catch(n){return p?.logger.debug("internal error",n),e}}function Un(t={}){y(()=>{if(typeof window>"u")return;let e=L();p?.close(),q?.(),p=new j(kt(t),window,e),Le();let n=()=>{y(Le,void 0);};document.addEventListener("turbo:load",n),q=()=>{document.removeEventListener("turbo:load",n);},O&&p.setRoute(O.name),O=void 0,t.debug===!0?Object.defineProperty(window,J,{value:{test:Tt},configurable:!0,writable:!0}):Reflect.deleteProperty(window,J);},void 0);}var J="__collector";function kt(t){let e={...t},n=t.dsn??E("collector-dsn"),r=t.environment??E("collector-environment"),o=t.release??E("collector-release");return n!==void 0&&(e.dsn=n),r!==void 0&&(e.environment=r),o!==void 0&&(e.release=o),e}function Le(){if(Z)return;let t=E("collector-user");L().setUser(t===void 0?null:{id:t});}async function Tt(){let t=()=>{let e="init() hasn't run on this page (or this isn't a browser).";return console.warn(`[collector] Test event not sent: ${e}`),{ok:false,reason:e}};return y(async()=>p?p.test():Promise.resolve(t()),Promise.resolve({ok:false,reason:"internal error."}))}function In(t,e){return y(()=>p?.captureException(t,e),void 0)}function $n(t,e){return y(()=>p?.captureMessage(t,e),void 0)}function Fn(t){y(()=>{Z=!0,L().setUser(t);},void 0);}function Bn(t,e){y(()=>{L().setTag(t,e);},void 0);}function Pn(t){y(()=>{L().setTags(t);},void 0);}function Dn(t){y(()=>{p?p.addBreadcrumb(t):Y.addBreadcrumb(t,50);},void 0);}async function jn(t){return y(async()=>p?.flush(t)??Promise.resolve(true),Promise.resolve(false))}function qn(t){y(()=>{p?p.setRoute(t):O={name:t};},void 0);}function Hn(){y(()=>{p?.close(),p=void 0,q?.(),q=void 0,Y=new S,O=void 0,Z=!1,typeof window<"u"&&Reflect.deleteProperty(window,J);},void 0);}re(import.meta.url);
|
|
7
|
+
export{Mn as SDK_VERSION,Dn as addBreadcrumb,In as captureException,$n as captureMessage,Hn as close,jn as flush,Un as init,qn as setRoute,Bn as setTag,Pn as setTags,Fn as setUser,Tt as test};
|