Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"@rrweb/rrweb-plugin-sequential-id-record",
"@rrweb/rrweb-plugin-sequential-id-replay",
"@rrweb/rrweb-plugin-canvas-webrtc-record",
"@rrweb/rrweb-plugin-canvas-webrtc-replay"
"@rrweb/rrweb-plugin-canvas-webrtc-replay",
"@rrweb/rrweb-plugin-network-record",
"@rrweb/rrweb-plugin-network-replay"
]
],
"linked": [],
Expand Down
7 changes: 7 additions & 0 deletions .changeset/six-lions-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rrweb/rrweb-plugin-network-record": minor
"@rrweb/rrweb-plugin-network-replay": minor
"@rrweb/types": minor
---

Add the network-plugin
12 changes: 11 additions & 1 deletion .vscode/rrweb-monorepo.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
{
"name": "@rrweb/rrweb-plugin-canvas-webrtc-replay",
"path": "../packages/plugins/rrweb-plugin-canvas-webrtc-replay"
},
{
"name": "@rrweb/rrweb-plugin-network-record",
"path": "../packages/plugins/rrweb-plugin-network-record"
},
{
"name": "@rrweb/rrweb-plugin-network-replay",
"path": "../packages/plugins/rrweb-plugin-network-replay"
}
],
"settings": {
Expand All @@ -98,7 +106,9 @@
"@rrweb/rrweb-plugin-console-replay",
"@rrweb/rrweb-plugin-sequential-id",
"@rrweb/rrweb-plugin-canvas-webrtc-record",
"@rrweb/rrweb-plugin-canvas-webrtc-replay"
"@rrweb/rrweb-plugin-canvas-webrtc-replay",
"@rrweb/rrweb-plugin-network-record",
"@rrweb/rrweb-plugin-network-replay"
],
"typescript.tsdk": " rrweb monorepo/node_modules/typescript/lib"
}
Expand Down
109 changes: 109 additions & 0 deletions docs/recipes/network.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# network recorder and replayer

This feature aims to provide developers with more information about the bug scene. There are some options for recording and replaying network output.

### Enable recording network

You can enable using default option like this:

```js
import { record } from '@rrweb/record';
import { getRecordNetworkPlugin } from '@rrweb/rrweb-plugin-network-record';

record({
emit: function emit(event) {
events.push(event);
},
// to use default record option
plugins: [getRecordNetworkPlugin()],
});
```

You can also customize the behavior of logger like this:

```js
import { record } from '@rrweb/record';
import { getRecordNetworkPlugin } from '@rrweb/rrweb-plugin-network-record';

const recordingId = crypto.randomUUID();

record({
emit: function emit(event) {
fetch(`https://api.rrweb.com/recordings/${recordingId}/events`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
events: [event],
}),
});
},
// customized record options
plugins: [
getRecordNetworkPlugin({
initiatorTypes: ['fetch', 'xmlhttprequest'],
// mask/block recording event for request
transformRequestFn: (request) => {
// request.name is url
if (request.name.includes('api.rrweb.com')) return; // skip request
delete request.requestHeaders?.Authorization; // remove sensitive data
request.responseBody = maskTextFn(request.responseBody);
return request;
},
recordHeaders: true,
recordBody: true,
recordInitialRequests: false,
}),
],
});
```

**alert**: If you are uploading events to a server, you should always use `transformRequestFn` to mask/block recording events for these requests or else you will cause a nasty loop.

All options are described below:

| key | default | description |
| --------------------- | -------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| initiatorTypes | `['fetch','xmlhttprequest','img',...]` | Default value contains names of all [initiator types](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming/initiatorType). You can override it by setting the types you need. |
| transformRequestFn | `(request) => request` | Transform recording event for request to block (skip) or mask/transform request (e.g. to hide sensitive data) |
| recordHeaders | `false` | Record the request & response headers for `fetch` and `xmlhttprequest` requests |
| recordBody | `false` | Record the request & response bodies for `fetch` and `xmlhttprequest` requests |
| recordInitialRequests | `false` | Record an event for all requests prior to `record()` being called |

## replay network

It is up to you to decide how to best replay your network events using the `onNetworkData` callback.

```js
import rrweb from 'rrweb';
import { getReplayNetworkPlugin } from '@rrweb/rrweb-plugin-network-replay';

const replayer = new rrweb.Replayer(events, {
plugins: [
getReplayNetworkPlugin({
onNetworkData: ({ requests }) => {
for (const request of requests) {
const name = request.name; // url
const method = request.method;
const status = request.status;
console.log(`${method} ${name} ${status}`);
}
},
}),
],
});
replayer.play();
```

Description of replay option is as follows:

| key | default | description |
| ------------- | ----------- | ------------------------------------------------------------------------------------------ |
| onNetworkData | `undefined` | You could use this interface to replay the network requests in a simulated browser console |

## technical implementation

This implementation records [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) and [`XMLHttpRequest`](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest) by patching their object & methods. We record document navigation using [`PerformanceNavigationTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceNavigationTiming) and we use [`PerformanceResourceTiming`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming) for recording everything else (script, img, link etc.) via [`PerformanceObserver`](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver) API.

For more information please see [[network-plugin] Feat: Capture network events #1105](https://github.com/rrweb-io/rrweb/pull/1105) PR.
2 changes: 2 additions & 0 deletions docs/recipes/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The plugin API is designed to extend the function of rrweb without bump the size
- [@rrweb/rrweb-plugin-sequential-id-replay](packages/plugins/rrweb-plugin-sequential-id-replay): A plugin for replaying sequential IDs.
- [@rrweb/rrweb-plugin-canvas-webrtc-record](packages/plugins/rrweb-plugin-canvas-webrtc-record): A plugin for stream `<canvas>` via WebRTC.
- [@rrweb/rrweb-plugin-canvas-webrtc-replay](packages/plugins/rrweb-plugin-canvas-webrtc-replay): A plugin for playing streamed `<canvas>` via WebRTC.
- [@rrweb/rrweb-plugin-network-record](packages/plugins/rrweb-plugin-network-record): A plugin for recording network requests (xhr/fetch).
- [@rrweb/rrweb-plugin-network-replay](packages/plugins/rrweb-plugin-network-replay): A plugin for replaying network requests (xhr/fetch).

## Interface

Expand Down
2 changes: 2 additions & 0 deletions docs/recipes/plugin.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- [@rrweb/rrweb-plugin-sequential-id-replay](packages/plugins/rrweb-plugin-sequential-id-replay):一个用于回放顺序 ID 的插件。
- [@rrweb/rrweb-plugin-canvas-webrtc-record](packages/plugins/rrweb-plugin-canvas-webrtc-record):一个用于通过 WebRTC 流式传输 `<canvas>` 的插件。
- [@rrweb/rrweb-plugin-canvas-webrtc-replay](packages/plugins/rrweb-plugin-canvas-webrtc-replay):一个用于通过 WebRTC 播放流式 `<canvas>` 的插件。
- [@rrweb/rrweb-plugin-network-record](packages/plugins/rrweb-plugin-network-record):一个用于记录网络请求的插件 (xhr/fetch)。
- [@rrweb/rrweb-plugin-network-replay](packages/plugins/rrweb-plugin-network-replay):一个用于回放网络请求的插件 (xhr/fetch)。

## 接口

Expand Down
2 changes: 2 additions & 0 deletions guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Besides the `@rrweb/record` and `@rrweb/replay` packages, rrweb also provides ot
- [@rrweb/rrweb-plugin-sequential-id-replay](packages/plugins/rrweb-plugin-sequential-id-replay): A plugin for replaying sequential IDs.
- [@rrweb/rrweb-plugin-canvas-webrtc-record](packages/plugins/rrweb-plugin-canvas-webrtc-record): A plugin for stream `<canvas>` via WebRTC.
- [@rrweb/rrweb-plugin-canvas-webrtc-replay](packages/plugins/rrweb-plugin-canvas-webrtc-replay): A plugin for playing streamed `<canvas>` via WebRTC.
- [@rrweb/rrweb-plugin-network-record](packages/plugins/rrweb-plugin-network-record): A plugin for recording network requests (xhr/fetch).
- [@rrweb/rrweb-plugin-network-replay](packages/plugins/rrweb-plugin-network-replay): A plugin for replaying network requests (xhr/fetch).

### Compatibility Note

Expand Down
2 changes: 2 additions & 0 deletions guide.zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ import '@rrweb/all/dist/style.css';
- [@rrweb/rrweb-plugin-sequential-id-replay](packages/plugins/rrweb-plugin-sequential-id-replay):一个用于回放顺序 ID 的插件。
- [@rrweb/rrweb-plugin-canvas-webrtc-record](packages/plugins/rrweb-plugin-canvas-webrtc-record):一个用于通过 WebRTC 流式传输 `<canvas>` 的插件。
- [@rrweb/rrweb-plugin-canvas-webrtc-replay](packages/plugins/rrweb-plugin-canvas-webrtc-replay):一个用于通过 WebRTC 播放流式 `<canvas>` 的插件。
- [@rrweb/rrweb-plugin-network-record](packages/plugins/rrweb-plugin-network-record):一个用于记录网络请求的插件 (xhr/fetch)。
- [@rrweb/rrweb-plugin-network-replay](packages/plugins/rrweb-plugin-network-replay):一个用于回放网络请求的插件 (xhr/fetch)。

### 兼容性

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"real-user-monitoring",
"rrweb"
],
"author": "yanzhen@smartx.com",
"author": "rrweb Core Team <maintainers@rrweb.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/rrweb-io/rrweb/issues"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"real-user-monitoring",
"rrweb"
],
"author": "justin@recordonce.com",
"author": "rrweb Core Team <maintainers@rrweb.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/rrweb-io/rrweb/issues"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"real-user-monitoring",
"rrweb"
],
"author": "justin@recordonce.com",
"author": "rrweb Core Team <maintainers@rrweb.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/rrweb-io/rrweb/issues"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/rrweb-plugin-console-record/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"real-user-monitoring",
"rrweb"
],
"author": "yanzhen@smartx.com",
"author": "rrweb Core Team <maintainers@rrweb.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/rrweb-io/rrweb/issues"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/rrweb-plugin-console-replay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"real-user-monitoring",
"rrweb"
],
"author": "yanzhen@smartx.com",
"author": "rrweb Core Team <maintainers@rrweb.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/rrweb-io/rrweb/issues"
Expand Down
Empty file.
Loading
Loading