@snapfail/browser 0.0.6 → 0.0.8
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/dist/collectors/network.d.ts +1 -1
- package/dist/index.js +12 -5
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NetworkEntry } from "@snapfail/protocol";
|
|
2
2
|
import { RingBuffer, type WithTimestamp } from "../buffer.ts";
|
|
3
3
|
type BufferedNetworkEntry = WithTimestamp<NetworkEntry>;
|
|
4
|
-
export declare function attachNetworkCollector(buffer: RingBuffer<BufferedNetworkEntry
|
|
4
|
+
export declare function attachNetworkCollector(buffer: RingBuffer<BufferedNetworkEntry>, snapfailEndpoint?: string): () => void;
|
|
5
5
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -4030,7 +4030,8 @@ var StackFrameSchema = exports_external.object({
|
|
|
4030
4030
|
file: exports_external.string(),
|
|
4031
4031
|
line: exports_external.number().optional(),
|
|
4032
4032
|
col: exports_external.number().optional(),
|
|
4033
|
-
fn: exports_external.string().optional()
|
|
4033
|
+
fn: exports_external.string().optional(),
|
|
4034
|
+
codeSnippet: exports_external.string().optional()
|
|
4034
4035
|
});
|
|
4035
4036
|
var NetworkEntrySchema = exports_external.object({
|
|
4036
4037
|
method: exports_external.string(),
|
|
@@ -4301,14 +4302,19 @@ function attachConsoleCollector(buffer) {
|
|
|
4301
4302
|
}
|
|
4302
4303
|
|
|
4303
4304
|
// src/collectors/network.ts
|
|
4304
|
-
function attachNetworkCollector(buffer) {
|
|
4305
|
+
function attachNetworkCollector(buffer, snapfailEndpoint) {
|
|
4305
4306
|
const originalFetch = window.fetch.bind(window);
|
|
4306
4307
|
const originalOpen = XMLHttpRequest.prototype.open;
|
|
4307
4308
|
const originalSend = XMLHttpRequest.prototype.send;
|
|
4309
|
+
function isSelf(url) {
|
|
4310
|
+
return !!snapfailEndpoint && url.startsWith(snapfailEndpoint);
|
|
4311
|
+
}
|
|
4308
4312
|
window.fetch = async (input, init) => {
|
|
4309
4313
|
const method = init?.method ?? "GET";
|
|
4310
4314
|
const url = scrubUrl(typeof input === "string" ? input : input instanceof URL ? input.href : input.url);
|
|
4311
4315
|
const start = Date.now();
|
|
4316
|
+
if (isSelf(url))
|
|
4317
|
+
return originalFetch(input, init);
|
|
4312
4318
|
let requestBodySize;
|
|
4313
4319
|
if (init?.body && typeof init.body === "string") {
|
|
4314
4320
|
requestBodySize = new TextEncoder().encode(init.body).length;
|
|
@@ -4344,7 +4350,8 @@ function attachNetworkCollector(buffer) {
|
|
|
4344
4350
|
};
|
|
4345
4351
|
const xhrMeta = new WeakMap;
|
|
4346
4352
|
XMLHttpRequest.prototype.open = function(method, url, ...rest) {
|
|
4347
|
-
|
|
4353
|
+
const scrubbedUrl = scrubUrl(String(url));
|
|
4354
|
+
xhrMeta.set(this, { method, url: scrubbedUrl, start: 0, skip: isSelf(scrubbedUrl) });
|
|
4348
4355
|
return originalOpen.call(this, method, url, ...rest);
|
|
4349
4356
|
};
|
|
4350
4357
|
XMLHttpRequest.prototype.send = function(body) {
|
|
@@ -4352,7 +4359,7 @@ function attachNetworkCollector(buffer) {
|
|
|
4352
4359
|
if (meta)
|
|
4353
4360
|
meta.start = Date.now();
|
|
4354
4361
|
this.addEventListener("loadend", () => {
|
|
4355
|
-
if (!meta)
|
|
4362
|
+
if (!meta || meta.skip)
|
|
4356
4363
|
return;
|
|
4357
4364
|
buffer.push({
|
|
4358
4365
|
method: meta.method,
|
|
@@ -4505,7 +4512,7 @@ function initSnapfail(config) {
|
|
|
4505
4512
|
const replayBuffer = new RingBuffer(windowMs);
|
|
4506
4513
|
const cleanups = [
|
|
4507
4514
|
attachConsoleCollector(consoleBuffer),
|
|
4508
|
-
attachNetworkCollector(networkBuffer),
|
|
4515
|
+
attachNetworkCollector(networkBuffer, config.endpoint),
|
|
4509
4516
|
attachReplayCollector(replayBuffer)
|
|
4510
4517
|
];
|
|
4511
4518
|
function triggerCapture(captured) {
|