@belvador/browser 0.0.0-stage → 0.2.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 +27 -0
- package/README.md +63 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.js +18 -0
- package/dist/internal.d.ts +30 -0
- package/dist/internal.js +85 -0
- package/package.json +48 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Belvador
|
|
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.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
This software depends on the Sentry JavaScript SDK (https://github.com/getsentry/sentry-javascript),
|
|
26
|
+
which is distributed under its own MIT License (Copyright (c) Functional Software, Inc. dba Sentry)
|
|
27
|
+
in each of its npm packages. Belvador is not affiliated with or endorsed by Sentry.
|
package/README.md
CHANGED
|
@@ -1,3 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @belvador/browser
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Error tracking for browser apps, sending to your [Belvador](https://belvador.dev) node.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @belvador/browser
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { init, captureException } from "@belvador/browser";
|
|
11
|
+
|
|
12
|
+
init({
|
|
13
|
+
dsn: "https://<key>@ingest.belvador.dev/<project>", // Project settings → DSN
|
|
14
|
+
release: import.meta.env.VITE_APP_VERSION, // your build or commit id
|
|
15
|
+
environment: import.meta.env.MODE,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
risky();
|
|
20
|
+
} catch (error) {
|
|
21
|
+
captureException(error);
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Uncaught errors and unhandled promise rejections are captured automatically. Only
|
|
26
|
+
`window.onerror` and `onunhandledrejection` are hooked by default; breadcrumbs from
|
|
27
|
+
`console`, `fetch`, `xhr`, DOM clicks and history are opt-in:
|
|
28
|
+
`init({ dsn, instrument: { fetch: true, console: true } })`.
|
|
29
|
+
|
|
30
|
+
Allow the ingest origin in your Content-Security-Policy: `connect-src https://ingest.belvador.dev`.
|
|
31
|
+
|
|
32
|
+
## What it sends
|
|
33
|
+
|
|
34
|
+
Errors only (exceptions, messages, breadcrumbs you turn on, attachments if you enable them).
|
|
35
|
+
No tracing, session replay, logs or profiling — those items are dropped inside your app.
|
|
36
|
+
|
|
37
|
+
Before anything leaves your app the SDK removes `Authorization`, `Cookie` and `Set-Cookie`
|
|
38
|
+
headers, request bodies and cookies, client IP headers, and masks credentials in URLs, query
|
|
39
|
+
strings, tags, contexts, extra data and breadcrumbs (passwords, tokens, API keys, JWTs, card
|
|
40
|
+
numbers, e-mail addresses). Only `user.id` is kept from `setUser`. Your Belvador node scrubs
|
|
41
|
+
again on its own.
|
|
42
|
+
|
|
43
|
+
Sending never slows down or breaks your app: at most 30 envelopes / 1 MB wait to be sent,
|
|
44
|
+
each attempt times out after 10 s, failed sends retry at most 5 times, `429` rate limits are
|
|
45
|
+
respected, and a revoked key (`401`/`403`) stops sending for the life of the page or isolate.
|
|
46
|
+
Every public function catches its own errors.
|
|
47
|
+
|
|
48
|
+
## Check the connection
|
|
49
|
+
|
|
50
|
+
"No errors" is not proof that errors arrive. Call `verifyIntegration()` from `@belvador/browser` once after `init`:
|
|
51
|
+
it sends one marked test error (never an issue), reads it back and resolves to
|
|
52
|
+
`{ outcome: "verified" | "problem" | "unconfirmed", checks, docsUrl, … }`. It never throws.
|
|
53
|
+
Requests the visitor cancelled (`AbortError`) are not reported unless you set `captureAborted: true`.
|
|
54
|
+
See https://belvador.dev/docs/sdk/verify
|
|
55
|
+
|
|
56
|
+
## Status
|
|
57
|
+
|
|
58
|
+
`0.x` — used by Belvador's own apps first. The API may still change before `1.0`.
|
|
59
|
+
|
|
60
|
+
Built on the open-source [Sentry JavaScript SDK](https://github.com/getsentry/sentry-javascript)
|
|
61
|
+
(MIT), pinned to one audited version, with Belvador's privacy and sending rules. Events go only
|
|
62
|
+
to your Belvador DSN; no Sentry account is involved. Belvador is not affiliated with Sentry.
|
|
63
|
+
|
|
64
|
+
License: MIT · https://belvador.dev
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { VerificationResult, VerifyOptions } from "@belvador/core";
|
|
2
|
+
import { type BrowserOptions } from "./internal.js";
|
|
3
|
+
export type { BrowserOptions } from "./internal.js";
|
|
4
|
+
export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, getDiagnostics, lastEventId, setContext, setTag, setTags, setUser, withScope, type BelvadorBreadcrumb, type BelvadorEvent, type BelvadorEventHint, type Diagnostic, type DiagnosticCode, type DiagnosticsSnapshot, type Scope, type SeverityLevel, type VerificationResult, type VerifyOptions, } from "@belvador/core";
|
|
5
|
+
/** Starts error tracking; returns whether it is running. Never throws. */
|
|
6
|
+
export declare function init(options: BrowserOptions): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Proves this page reports to Belvador: a captured and an uncaught verification error
|
|
9
|
+
* (the console shows one "expected" error), read back from Belvador. Run it once after
|
|
10
|
+
* setup or deploy; never automatic. Always resolves; prints one summary line.
|
|
11
|
+
*/
|
|
12
|
+
export declare function verifyIntegration(options?: VerifyOptions): Promise<VerificationResult>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @belvador/browser — errors from the browser to your Belvador node.
|
|
2
|
+
// Built on the open-source Sentry JavaScript SDK (MIT), with Belvador's
|
|
3
|
+
// privacy and sending rules. Importing this module does nothing until init().
|
|
4
|
+
import { init as engineInit } from "@sentry/browser";
|
|
5
|
+
import { initWith, verifyBrowser } from "./internal.js";
|
|
6
|
+
export { SDK_VERSION, addBreadcrumb, captureException, captureMessage, close, flush, getDiagnostics, lastEventId, setContext, setTag, setTags, setUser, withScope, } from "@belvador/core";
|
|
7
|
+
/** Starts error tracking; returns whether it is running. Never throws. */
|
|
8
|
+
export function init(options) {
|
|
9
|
+
return initWith(engineInit, options, "browser");
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Proves this page reports to Belvador: a captured and an uncaught verification error
|
|
13
|
+
* (the console shows one "expected" error), read back from Belvador. Run it once after
|
|
14
|
+
* setup or deploy; never automatic. Always resolves; prints one summary line.
|
|
15
|
+
*/
|
|
16
|
+
export function verifyIntegration(options) {
|
|
17
|
+
return verifyBrowser(options);
|
|
18
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { BrowserOptions as EngineBrowserOptions } from "@sentry/browser";
|
|
2
|
+
import { type BelvadorOptions, type RuntimeName, type VerificationResult, type VerifyOptions } from "@belvador/core";
|
|
3
|
+
export type BrowserOptions = BelvadorOptions & {
|
|
4
|
+
/** Breadcrumb sources, all off by default (each one patches a browser API). */
|
|
5
|
+
instrument?: {
|
|
6
|
+
console?: boolean;
|
|
7
|
+
dom?: boolean;
|
|
8
|
+
fetch?: boolean;
|
|
9
|
+
xhr?: boolean;
|
|
10
|
+
history?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** Wrap setTimeout/addEventListener/requestAnimationFrame for better stacks. Default false. */
|
|
13
|
+
wrapBrowserApis?: boolean;
|
|
14
|
+
allowUrls?: Array<string | RegExp>;
|
|
15
|
+
/** Added to the built-in browser-extension filter. */
|
|
16
|
+
denyUrls?: Array<string | RegExp>;
|
|
17
|
+
};
|
|
18
|
+
/** Engine options for a browser runtime, or null when the SDK must stay off. */
|
|
19
|
+
export declare function browserEngineOptions(options: BrowserOptions, runtime: Extract<RuntimeName, "browser" | "react" | "tanstack-start">): EngineBrowserOptions | null;
|
|
20
|
+
/**
|
|
21
|
+
* Idempotent init: a second call with the same DSN keeps the running client
|
|
22
|
+
* (HMR, StrictMode); a different DSN or another SDK's client is never
|
|
23
|
+
* replaced silently. Returns whether Belvador is running. Never throws.
|
|
24
|
+
*/
|
|
25
|
+
export declare function initWith(engineInit: (options: EngineBrowserOptions) => unknown, options: BrowserOptions, runtime: Extract<RuntimeName, "browser" | "react" | "tanstack-start">): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Browser verification (integration-health spec 02 §3): the global error handler is
|
|
28
|
+
* installed, a captured verification arrives, and an uncaught one does too.
|
|
29
|
+
*/
|
|
30
|
+
export declare function verifyBrowser(options?: VerifyOptions): Promise<VerificationResult>;
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Shared by @belvador/browser, /react and /tanstack-start: browser engine
|
|
2
|
+
// options and the idempotent init. Not a public API.
|
|
3
|
+
import { breadcrumbsIntegration, browserApiErrorsIntegration, dedupeIntegration, eventFiltersIntegration, functionToStringIntegration, getClient, globalHandlersIntegration, httpContextIntegration, linkedErrorsIntegration, } from "@sentry/browser";
|
|
4
|
+
import { BELVADOR_MARKER, buildEngineOptions, isActive, reportDiagnostic, runVerification, warnOnce, } from "@belvador/core";
|
|
5
|
+
const EXTENSION_URLS = [
|
|
6
|
+
/^chrome-extension:\/\//i,
|
|
7
|
+
/^moz-extension:\/\//i,
|
|
8
|
+
/^safari-(web-)?extension:\/\//i,
|
|
9
|
+
];
|
|
10
|
+
/** Engine options for a browser runtime, or null when the SDK must stay off. */
|
|
11
|
+
export function browserEngineOptions(options, runtime) {
|
|
12
|
+
const base = buildEngineOptions(options, runtime, { browser: true });
|
|
13
|
+
if (!base)
|
|
14
|
+
return null;
|
|
15
|
+
const i = options.instrument ?? {};
|
|
16
|
+
const crumbs = {
|
|
17
|
+
console: i.console === true,
|
|
18
|
+
dom: i.dom === true,
|
|
19
|
+
fetch: i.fetch === true,
|
|
20
|
+
xhr: i.xhr === true,
|
|
21
|
+
history: i.history === true,
|
|
22
|
+
sentry: false,
|
|
23
|
+
};
|
|
24
|
+
// Only window.onerror and onunhandledrejection by default (t4 §A).
|
|
25
|
+
const integrations = [
|
|
26
|
+
eventFiltersIntegration(),
|
|
27
|
+
linkedErrorsIntegration(),
|
|
28
|
+
dedupeIntegration(),
|
|
29
|
+
globalHandlersIntegration({ onerror: true, onunhandledrejection: true }),
|
|
30
|
+
httpContextIntegration(),
|
|
31
|
+
];
|
|
32
|
+
if (crumbs.console || crumbs.dom || crumbs.fetch || crumbs.xhr || crumbs.history)
|
|
33
|
+
integrations.push(breadcrumbsIntegration(crumbs));
|
|
34
|
+
if (options.wrapBrowserApis === true)
|
|
35
|
+
integrations.push(functionToStringIntegration(), browserApiErrorsIntegration());
|
|
36
|
+
return {
|
|
37
|
+
...base,
|
|
38
|
+
integrations,
|
|
39
|
+
...(Array.isArray(options.allowUrls) ? { allowUrls: options.allowUrls } : {}),
|
|
40
|
+
denyUrls: [...EXTENSION_URLS, ...(Array.isArray(options.denyUrls) ? options.denyUrls : [])],
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Idempotent init: a second call with the same DSN keeps the running client
|
|
45
|
+
* (HMR, StrictMode); a different DSN or another SDK's client is never
|
|
46
|
+
* replaced silently. Returns whether Belvador is running. Never throws.
|
|
47
|
+
*/
|
|
48
|
+
export function initWith(engineInit, options, runtime) {
|
|
49
|
+
try {
|
|
50
|
+
const existing = getClient();
|
|
51
|
+
if (existing) {
|
|
52
|
+
const prev = existing.getOptions();
|
|
53
|
+
if (prev[BELVADOR_MARKER] === true && prev["dsn"] === options?.dsn)
|
|
54
|
+
return true;
|
|
55
|
+
reportDiagnostic("BLV_INIT_CONFLICT");
|
|
56
|
+
warnOnce("init skipped: another error-tracking client is already running in this page. Remove the old init so errors are not captured twice.");
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const engineOptions = browserEngineOptions(options, runtime);
|
|
60
|
+
if (!engineOptions)
|
|
61
|
+
return false;
|
|
62
|
+
engineInit(engineOptions);
|
|
63
|
+
return isActive();
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Browser verification (integration-health spec 02 §3): the global error handler is
|
|
71
|
+
* installed, a captured verification arrives, and an uncaught one does too.
|
|
72
|
+
*/
|
|
73
|
+
export function verifyBrowser(options) {
|
|
74
|
+
return runVerification({
|
|
75
|
+
surface: "browser",
|
|
76
|
+
hook: () => {
|
|
77
|
+
try {
|
|
78
|
+
return { ok: Boolean(getClient()?.getIntegrationByName("GlobalHandlers")) };
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return { ok: false };
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
}, options);
|
|
85
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@belvador/browser",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Belvador error tracking for the browser: one init, errors only, private by default.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Belvador (https://belvador.dev)",
|
|
7
|
+
"homepage": "https://belvador.dev",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"belvador",
|
|
10
|
+
"error-tracking",
|
|
11
|
+
"errors",
|
|
12
|
+
"monitoring"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"sideEffects": false,
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./internal": {
|
|
25
|
+
"types": "./dist/internal.d.ts",
|
|
26
|
+
"import": "./dist/internal.js",
|
|
27
|
+
"default": "./dist/internal.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@belvador/core": "0.2.0",
|
|
41
|
+
"@sentry/browser": "10.76.2"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"tag": "latest"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -p tsconfig.json"
|
|
49
|
+
}
|
|
50
|
+
}
|