# @openreplay/network-proxy

> this library helps us to create proxy objects for fetch, XHR and beacons for proper request tracking.

Latest version **1.2.7** (published 2026-09-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install @openreplay/network-proxy
pnpm add @openreplay/network-proxy
yarn add @openreplay/network-proxy
bun add @openreplay/network-proxy
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.2.7 |
| Published | 2026-09-29 |
| First published | 2024-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 103.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Nikita |
| Maintainers | shekarsiri, estradino, deliriumvt, tahayk |

## Links

- npm: https://www.npmjs.com/package/@openreplay/network-proxy
- npm.io page: https://npm.io/package/@openreplay/network-proxy

## Recent versions

- 1.2.7 (latest) — 2026-09-29
- 1.2.1-beta.0 (beta) — 2025-09-16
- 1.2.6 — 2026-09-28
- 1.2.5 — 2026-05-22
- 1.2.4 — 2026-04-21
- 1.2.3 — 2026-04-20
- 1.2.2 — 2025-10-13
- 1.2.0 — 2025-07-31
- 1.1.4 — 2025-07-15
- 1.1.3 — 2025-04-17
- 1.1.2 — 2025-04-16
- 1.1.1 — 2025-04-14
- 1.1.0 — 2025-03-25
- 1.1.0-beta.1 — 2025-03-25
- 1.1.0-beta.0 — 2025-03-25
- … 6 more at https://npm.io/package/@openreplay/network-proxy/versions

## README

this tiny library helps us (OpenReplay folks) to create proxy objects for fetch,
XHR and beacons for proper request tracking in @openreplay/tracker and Spot extension.

example usage:
```
import createNetworkProxy from '@openreplay/network-proxy';

const context = this;
const ignoreHeaders = ['Authorization'];
const tokenUrlMatcher = /\/auth\/token/;
function setSessionTokenHeader(setRequestHeader: (name: string, value: string) => void) {
  const header = 'X-Session-Token
  const sessionToken = getToken() // for exmaple, => `session #123123`;
  if (sessionToken) {
    setRequestHeader(header, sessionToken)
  }
}
function sanitize(reqResInfo) {
  if (reqResInfo.request) {
    delete reqResInfo.request.body
  }
  return reqResInfo
}

const onMsg = (networkReq) => console.log(networkReq)
const isIgnoredUrl = (url) => url.includes('google.com')

// Gets current tracker request’s url and returns boolean. If present,
// sessionTokenHeader will only be applied when this function returns true.
// Default: undefined
const tokenUrlMatcher = (url) => url.includes('google.com');

// this will observe global network requests
createNetworkProxy(
  context,
  options.ignoreHeaders,
  setSessionTokenHeader,
  sanitize,
  (message) => app.send(message),
  (url) => app.isServiceURL(url),
  options.tokenUrlMatcher,
)

// to stop it, you can save this.fetch/other apis before appliying the proxy
// and then restore them
```

axios instances with a custom adapter (native HTTP bridge, mock, `env.fetch`) never reach
the global XHR/fetch, hook them explicitly. Requests that went through the proxies are
skipped, so hooking an instance with the default adapter records nothing twice:
```
import { hookAxios } from '@openreplay/network-proxy';

hookAxios(
  api, // axios.create(...)
  options.ignoreHeaders,
  setSessionTokenHeader,
  sanitize,
  (message) => app.send(message),
  (url) => app.isServiceURL(url),
  options.tokenUrlMatcher,
)
```

---
_Source: https://npm.io/package/@openreplay/network-proxy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
