@oxvo/network-instrumentation
v1.0.1
Published
Network proxy layer for OxvoSessions browser instrumentation across fetch, XMLHttpRequest, and sendBeacon.
Readme
OxvoSessions Network Instrumentation
@oxvo/network-instrumentation is the shared proxy layer used by OxvoSessions browser tooling to observe fetch, XMLHttpRequest, and navigator.sendBeacon traffic without changing application request code.
It is intended for controlled SDK integrations where you need consistent request capture, header filtering, session-token injection, and payload sanitization before events are forwarded downstream.
Install
npm install @oxvo/network-instrumentationExample
import createNetworkProxy from "@oxvo/network-instrumentation";
const ignoredHeaders = ["authorization", "cookie"];
const setSessionTokenHeader = (
setRequestHeader: (name: string, value: string) => void,
) => {
const siteSessionToken = "session-123";
if (siteSessionToken) {
setRequestHeader("X-Session-Token", siteSessionToken);
}
};
const sanitize = (requestResponse: any) => {
if (requestResponse?.request?.body) {
delete requestResponse.request.body;
}
return requestResponse;
};
createNetworkProxy(
window,
ignoredHeaders,
setSessionTokenHeader,
sanitize,
(message) => {
console.log("network event", message);
},
(url) => url.includes("/internal/health"),
{
xhr: true,
fetch: true,
beacon: true,
},
(url) => url.includes("/api"),
);Integration Notes
- Pass
windowin browser environments andglobalThisin test or non-DOM runtimes. - Keep ignored header names lowercase so filtering remains predictable across transport types.
- Use
sanitizeto remove secrets or large bodies before forwarding captured traffic. - Provide a
tokenUrlMatcheronly when the session token header should be limited to selected endpoints. - If you need to disable instrumentation, restore the original
fetch,XMLHttpRequest, orsendBeaconreferences that your application saved before proxying.
Exported API
The package exports:
createNetworkProxyas the default exportFetchProxyXHRProxyBeaconProxyINetworkMessageRequestResponseData
