@watchupltd/browser 1.0.0 → 1.0.2
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 +280 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# @watchupltd/browser
|
|
2
|
+
|
|
3
|
+
Browser runtime integration for incident tracking in vanilla JavaScript/TypeScript applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @watchupltd/browser
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Basic Setup
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { init } from '@watchupltd/browser';
|
|
17
|
+
|
|
18
|
+
const client = init({
|
|
19
|
+
apiKey: 'your-api-key',
|
|
20
|
+
projectId: 'your-project-id',
|
|
21
|
+
environment: 'production',
|
|
22
|
+
captureConsoleErrors: true // Optional: capture console.error calls
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Manual Error Capture
|
|
27
|
+
|
|
28
|
+
```javascript
|
|
29
|
+
try {
|
|
30
|
+
riskyOperation();
|
|
31
|
+
} catch (error) {
|
|
32
|
+
client.captureError(error, {
|
|
33
|
+
tags: { section: 'checkout' },
|
|
34
|
+
extra: { orderId: '12345' }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Capture Messages
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
client.captureMessage('Payment processed successfully', 'info');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Set User Context
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
client.setUser({
|
|
49
|
+
id: 'user-123',
|
|
50
|
+
email: 'user@example.com',
|
|
51
|
+
username: 'john_doe'
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Add Breadcrumbs
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
client.addBreadcrumb({
|
|
59
|
+
message: 'User clicked checkout button',
|
|
60
|
+
category: 'user-action',
|
|
61
|
+
level: 'info'
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Add Tags
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
client.setTag('version', '1.2.3');
|
|
69
|
+
client.setTags({
|
|
70
|
+
browser: 'chrome',
|
|
71
|
+
os: 'windows'
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## What It Tracks
|
|
76
|
+
|
|
77
|
+
### Automatic Tracking
|
|
78
|
+
|
|
79
|
+
- **Global JavaScript Errors**: Captures all uncaught errors via `window.onerror`
|
|
80
|
+
- **Unhandled Promise Rejections**: Captures via `window.onunhandledrejection`
|
|
81
|
+
- **Console Errors**: Optionally captures `console.error()` calls
|
|
82
|
+
|
|
83
|
+
### Manual Tracking
|
|
84
|
+
|
|
85
|
+
- Custom errors via `captureError()`
|
|
86
|
+
- Log messages via `captureMessage()`
|
|
87
|
+
- User actions via `addBreadcrumb()`
|
|
88
|
+
|
|
89
|
+
## Configuration Options
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
interface BrowserConfig {
|
|
93
|
+
apiKey: string; // Required: Your API key
|
|
94
|
+
projectId: string; // Required: Your project ID
|
|
95
|
+
endpoint?: string; // Optional: Custom API endpoint
|
|
96
|
+
environment?: string; // Optional: Environment (default: 'production')
|
|
97
|
+
batchInterval?: number; // Optional: Batch interval in ms (default: 5000)
|
|
98
|
+
maxBatchSize?: number; // Optional: Max events per batch (default: 10)
|
|
99
|
+
maxRetries?: number; // Optional: Max retry attempts (default: 3)
|
|
100
|
+
enabled?: boolean; // Optional: Enable/disable SDK (default: true)
|
|
101
|
+
captureConsoleErrors?: boolean; // Optional: Capture console.error (default: false)
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Data Models
|
|
106
|
+
|
|
107
|
+
### Event Model
|
|
108
|
+
|
|
109
|
+
```json
|
|
110
|
+
{
|
|
111
|
+
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
112
|
+
"project_id": "proj_abc123",
|
|
113
|
+
"fingerprint": "a1b2c3d4e5f6...",
|
|
114
|
+
"title": "ValueError",
|
|
115
|
+
"message": "Invalid user input: expected integer",
|
|
116
|
+
"stack_trace": "Traceback (most recent call last):\n File \"app.py\", line 42...",
|
|
117
|
+
"service": "frontend",
|
|
118
|
+
"environment": "production",
|
|
119
|
+
"severity": "error",
|
|
120
|
+
"timestamp": 1678901234567,
|
|
121
|
+
"platform": "javascript",
|
|
122
|
+
"release": "1.2.3",
|
|
123
|
+
"server_name": "web-app-01",
|
|
124
|
+
"metadata": {
|
|
125
|
+
"custom_key": "custom_value"
|
|
126
|
+
},
|
|
127
|
+
"user": {
|
|
128
|
+
"id": "user-123",
|
|
129
|
+
"email": "user@example.com",
|
|
130
|
+
"username": "john_doe",
|
|
131
|
+
"ip_address": "192.168.1.1"
|
|
132
|
+
},
|
|
133
|
+
"tags": {
|
|
134
|
+
"component": "payment",
|
|
135
|
+
"version": "1.2.3"
|
|
136
|
+
},
|
|
137
|
+
"breadcrumbs": [
|
|
138
|
+
{
|
|
139
|
+
"timestamp": 1678901230000,
|
|
140
|
+
"message": "User logged in",
|
|
141
|
+
"category": "auth",
|
|
142
|
+
"level": "info",
|
|
143
|
+
"data": {}
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"context": {
|
|
147
|
+
"browser": {
|
|
148
|
+
"name": "Chrome",
|
|
149
|
+
"version": "120.0.0"
|
|
150
|
+
},
|
|
151
|
+
"os": {
|
|
152
|
+
"name": "Windows",
|
|
153
|
+
"version": "10.0"
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### User Model
|
|
160
|
+
|
|
161
|
+
```json
|
|
162
|
+
{
|
|
163
|
+
"id": "user-123",
|
|
164
|
+
"email": "user@example.com",
|
|
165
|
+
"username": "john_doe",
|
|
166
|
+
"ip_address": "192.168.1.1"
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Breadcrumb Model
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"timestamp": 1678901234567,
|
|
175
|
+
"message": "User action description",
|
|
176
|
+
"category": "user-action | navigation | http | database | console",
|
|
177
|
+
"level": "fatal | error | warning | info | debug",
|
|
178
|
+
"data": {
|
|
179
|
+
"key": "value"
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Use Cases
|
|
185
|
+
|
|
186
|
+
Perfect for:
|
|
187
|
+
- Vanilla JavaScript applications
|
|
188
|
+
- TypeScript applications without frameworks
|
|
189
|
+
- Static websites with custom JavaScript
|
|
190
|
+
- Browser extensions
|
|
191
|
+
- Bookmarklets
|
|
192
|
+
- Any web application not using React/Vue/Angular/etc.
|
|
193
|
+
|
|
194
|
+
## Example: Complete Setup
|
|
195
|
+
|
|
196
|
+
```html
|
|
197
|
+
<!DOCTYPE html>
|
|
198
|
+
<html>
|
|
199
|
+
<head>
|
|
200
|
+
<title>My App</title>
|
|
201
|
+
</head>
|
|
202
|
+
<body>
|
|
203
|
+
<button id="testBtn">Test Error</button>
|
|
204
|
+
|
|
205
|
+
<script type="module">
|
|
206
|
+
import { init } from '@watchupltd/browser';
|
|
207
|
+
|
|
208
|
+
// Initialize
|
|
209
|
+
const client = init({
|
|
210
|
+
apiKey: 'your-api-key',
|
|
211
|
+
projectId: 'your-project-id',
|
|
212
|
+
environment: 'production',
|
|
213
|
+
captureConsoleErrors: true
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// Set user context
|
|
217
|
+
client.setUser({
|
|
218
|
+
id: '123',
|
|
219
|
+
email: 'user@example.com'
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Add breadcrumb
|
|
223
|
+
client.addBreadcrumb({
|
|
224
|
+
message: 'Page loaded',
|
|
225
|
+
category: 'navigation'
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// Manual error capture
|
|
229
|
+
document.getElementById('testBtn').addEventListener('click', () => {
|
|
230
|
+
try {
|
|
231
|
+
throw new Error('Test error');
|
|
232
|
+
} catch (error) {
|
|
233
|
+
client.captureError(error, {
|
|
234
|
+
tags: { source: 'button-click' }
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
</script>
|
|
239
|
+
</body>
|
|
240
|
+
</html>
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## TypeScript Support
|
|
244
|
+
|
|
245
|
+
Full TypeScript support with type definitions included.
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
import { init, getClient, IncidentClient } from '@watchupltd/browser';
|
|
249
|
+
import type { BrowserConfig, SeverityLevel } from '@watchupltd/browser';
|
|
250
|
+
|
|
251
|
+
const config: BrowserConfig = {
|
|
252
|
+
apiKey: 'your-api-key',
|
|
253
|
+
projectId: 'your-project-id'
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const client: IncidentClient = init(config);
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## API Reference
|
|
260
|
+
|
|
261
|
+
### `init(config: BrowserConfig): IncidentClient`
|
|
262
|
+
Initialize the browser SDK and set up global error handlers.
|
|
263
|
+
|
|
264
|
+
### `getClient(): IncidentClient | null`
|
|
265
|
+
Get the current client instance.
|
|
266
|
+
|
|
267
|
+
### `IncidentClient` Methods
|
|
268
|
+
|
|
269
|
+
- `captureError(error: Error, context?: EventContext): Promise<string | null>`
|
|
270
|
+
- `captureMessage(message: string, level?: SeverityLevel, context?: EventContext): Promise<string | null>`
|
|
271
|
+
- `addBreadcrumb(breadcrumb: Breadcrumb): void`
|
|
272
|
+
- `setUser(user: User | null): void`
|
|
273
|
+
- `setTag(key: string, value: string): void`
|
|
274
|
+
- `setTags(tags: Record<string, string>): void`
|
|
275
|
+
- `flush(): Promise<void>`
|
|
276
|
+
- `close(): void`
|
|
277
|
+
|
|
278
|
+
## License
|
|
279
|
+
|
|
280
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@watchupltd/browser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.mjs",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
16
|
-
"dev": "tsup src/index.ts --format cjs,esm --dts --watch"
|
|
15
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --external @watchupltd/core --no-splitting",
|
|
16
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --external @watchupltd/core --no-splitting --watch"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@watchupltd/core": "
|
|
19
|
+
"@watchupltd/core": "^1.0.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"tsup": "^7.0.0",
|