update docs
This commit is contained in:
46
README.md
46
README.md
@@ -1,3 +1,10 @@
|
||||
<p align="center">
|
||||
<img width="100px" height="100px" src="https://www.rrweb.io/favicon.png">
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://www.rrweb.io/" style="font-weight: bold">Try rrweb</a>
|
||||
</p>
|
||||
|
||||
# rrweb
|
||||
|
||||
[](https://travis-ci.org/rrweb-io/rrweb)
|
||||
@@ -8,6 +15,10 @@ rrweb refers to 'record and replay the web', which is a tool for recording and r
|
||||
|
||||
**Currently, rrweb has already solved many difficult problems in recording and replaying, but the data structure may still be changed before the release of Version 1.0. So please be cautious to use rrweb in the production environment.**
|
||||
|
||||
## Guide
|
||||
|
||||
[**📚 Read the rrweb guide here. 📚**](./guide.md)
|
||||
|
||||
## Project Structure
|
||||
|
||||
rrweb is mainly composed of 3 parts:
|
||||
@@ -31,12 +42,12 @@ rrweb is mainly composed of 3 parts:
|
||||
- hijack Ajax/fetch API and record request events
|
||||
- use TraceKit to log exception events
|
||||
|
||||
## Internal Design
|
||||
<!-- ## Internal Design
|
||||
|
||||
- [serialization](./docs/serialization.md)
|
||||
- [incremental snapshot](./docs/observer.md)
|
||||
- [replay](./docs/replay.md)
|
||||
- [sandbox](./docs/sandbox.md)
|
||||
- [sandbox](./docs/sandbox.md) -->
|
||||
|
||||
## Contribute Guide
|
||||
|
||||
@@ -51,33 +62,4 @@ Since we want the record and replay sides to share a strongly typed data structu
|
||||
|
||||
In addition to adding integration tests and unit tests, rrweb also provides a REPL testing tool.
|
||||
|
||||
Run `npm run repl` to launch a browser and ask for a URL you want to test on the CLI:
|
||||
|
||||
```
|
||||
Enter the url you want to record, e.g https://react-redux.realworld.io:
|
||||
```
|
||||
|
||||
Waiting for the browser to open the specified page and print following messages on the CLI:
|
||||
|
||||
```
|
||||
Enter the url you want to record, e.g https://react-redux.realworld.io: https://github.com
|
||||
Going to open https://github.com...
|
||||
Ready to record. You can do any interaction on the page.
|
||||
Once you want to finish the recording, enter 'y' to start replay:
|
||||
```
|
||||
|
||||
At this point, you can interact in the web page. After the desired operations have been recorded, enter 'y' on the CLI, and the test tool will replay the operations to verify whether the recording was successful.
|
||||
|
||||
The following messages will be printed on the CLI during replay:
|
||||
|
||||
```
|
||||
Enter 'y' to persistently store these recorded events:
|
||||
```
|
||||
|
||||
At this point, you can enter 'y' again on the CLI. The test tool will save the recorded session into a static HTML file and prompt for the location:
|
||||
|
||||
```
|
||||
Saved at PATH_TO_YOUR_REPO/temp/replay_2018_11_23T07_53_30.html
|
||||
```
|
||||
|
||||
This file uses the latest rrweb bundle code, so we can run `npm run bundle:browser` after patching the code, then refresh the static file to see and debug the impact of the latest code on replay.
|
||||
[Using the REPL tool](./guide.md#REPL-tool)
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
<p align="center">
|
||||
<img width="100px" height="100px" src="https://www.rrweb.io/favicon.png">
|
||||
</p>
|
||||
<p align="center">
|
||||
<a href="https://www.rrweb.io/" style="font-weight: bold">Try rrweb</a>
|
||||
</p>
|
||||
|
||||
# rrweb
|
||||
|
||||
[](https://travis-ci.org/rrweb-io/rrweb)
|
||||
@@ -6,6 +13,10 @@ rrweb 是 'record and replay the web' 的简写,旨在利用现代浏览器所
|
||||
|
||||
**目前 rrweb 已经解决了许多录制与回放中的难点问题,但在 1.0 版本 release 之前数据结构仍有可能发生变化,请谨慎用于生产环境中。**
|
||||
|
||||
## 指南
|
||||
|
||||
[**📚 rrweb 使用指南 📚**](./guide.zh_CN.md)
|
||||
|
||||
## 项目结构
|
||||
|
||||
rrweb 主要由 3 部分组成:
|
||||
|
||||
237
guide.md
Normal file
237
guide.md
Normal file
@@ -0,0 +1,237 @@
|
||||
# Guide
|
||||
|
||||
[中文指南](./guide.zh_CN.md)
|
||||
|
||||
## Installation
|
||||
|
||||
### Direct `<script>` include
|
||||
|
||||
You are recommended to install rrweb via jsdelivr's CDN service:
|
||||
|
||||
```html
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/rrweb@latest/dist/rrweb.min.css"
|
||||
/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/rrweb@latest/dist/rrweb.min.js"></script>
|
||||
```
|
||||
|
||||
Also, you can link to a specific version number that you can update manually:
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/rrweb@0.7.0/dist/rrweb.min.js"></script>
|
||||
```
|
||||
|
||||
#### Only include the recorder code
|
||||
|
||||
rrweb's code includes both the record and the replay parts. Most of the time you only need include the record part into your target web Apps.
|
||||
This also can be done by using the CDN service:
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/rrweb@latest/dist/record/rrweb-record.min.js"></script>
|
||||
```
|
||||
|
||||
### NPM
|
||||
|
||||
```shell
|
||||
npm install --save rrweb
|
||||
```
|
||||
|
||||
rrweb provides both commonJS and ES modules bundles, which is easy to use with the popular bundlers.
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Record
|
||||
|
||||
If you only include record code with `<script>`, then you can use the global variable `rrwebRecord` which is the same as `rrweb.record`.
|
||||
The following sample codes will use `rrweb` variable the default exporter of this library.
|
||||
|
||||
```js
|
||||
rrweb.record({
|
||||
emit(event) {
|
||||
// store the event in any way you like
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
During recording, the recorder will emit when there is some event incurred, all you need to do is to store the emitted events in any way you like.
|
||||
|
||||
A more real-world usage may looks like this:
|
||||
|
||||
```js
|
||||
let events = [];
|
||||
|
||||
rrweb.record({
|
||||
emit(event) {
|
||||
// push event into the events array
|
||||
events.push(event);
|
||||
},
|
||||
});
|
||||
|
||||
// this function will send events to the backend and reset the events array
|
||||
function save() {
|
||||
const body = JSON.stringify({ events });
|
||||
events = [];
|
||||
fetch('http://YOUR_BACKEND_API', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body,
|
||||
});
|
||||
}
|
||||
|
||||
// save events every 10 seconds
|
||||
setInterval(save, 10 * 1000);
|
||||
```
|
||||
|
||||
#### Privacy
|
||||
|
||||
You may found some contents on the webpage were not willing to be recorded, then you can use the following approaches:
|
||||
|
||||
- An element with the class name `.rr-block` will not be recorded. Instead, it will replay as a placeholder with the same dimension.
|
||||
- An element with the class name `.rr-ignore` will not record its input events.
|
||||
- `input[type="password"]` will be ignored as default.
|
||||
|
||||
### Replay
|
||||
|
||||
You need to include the style sheet before replay:
|
||||
|
||||
```html
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/rrweb@latest/dist/rrweb.min.css"
|
||||
/>
|
||||
```
|
||||
|
||||
And then initialize the replayer with the following code:
|
||||
|
||||
```js
|
||||
const events = YOUR_EVENTS;
|
||||
|
||||
const replayer = new rrweb.Replayer(events);
|
||||
replayer.play();
|
||||
```
|
||||
|
||||
#### Options
|
||||
|
||||
The replayer accepts options as its constructor's second parameter, and it has the following options:
|
||||
|
||||
| key | default | description |
|
||||
| ------------ | ------------- | ------------------------------------- |
|
||||
| speed | 1 | replay speed ratio |
|
||||
| root | document.body | the root element of replayer |
|
||||
| loadTimeout | 0 | timeout of loading remote style sheet |
|
||||
| skipInactive | false | whether to skip inactive time |
|
||||
|
||||
#### Use rrweb-player
|
||||
|
||||
Since rrweb's replayer only provides a basic UI, you can choose rrweb-replayer which was based on rrweb's public APIs but has a feature-rich replayer UI.
|
||||
|
||||
##### Installation
|
||||
|
||||
rrweb-player can also be included with `<script>`:
|
||||
|
||||
```html
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/rrweb-player@latest/dist/style.css"
|
||||
/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/rrweb-player@latest/dist/index.js"></script>
|
||||
```
|
||||
|
||||
Or installed by using NPM:
|
||||
|
||||
```shell
|
||||
npm install --save rrweb-player
|
||||
```
|
||||
|
||||
##### Usage
|
||||
|
||||
```js
|
||||
new rrwebPlayer({
|
||||
target: document.body, // customizable root element
|
||||
data: {
|
||||
events,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### rrweb
|
||||
|
||||
#### rrweb.record
|
||||
|
||||
```typescript
|
||||
type record = (options: recordOptions) => listenerHandler;
|
||||
|
||||
type recordOptions = {
|
||||
emit: (e: eventWithTime) => void;
|
||||
};
|
||||
type listenerHandler = () => void;
|
||||
```
|
||||
|
||||
#### rrweb.Replayer
|
||||
|
||||
```typescript
|
||||
class Replayer {
|
||||
public wrapper: HTMLDivElement;
|
||||
|
||||
constructor(events: eventWithTime[], config?: Partial<playerConfig>);
|
||||
|
||||
public on(event: string, handler: mitt.Handler): void;
|
||||
public setConfig(config: Partial<playerConfig>): void;
|
||||
public getMetaData(): playerMetaData;
|
||||
public getTimeOffset(): number;
|
||||
public play(timeOffset?: number): void;
|
||||
public pause(): void;
|
||||
public resume(timeOffset?: number): void;
|
||||
}
|
||||
|
||||
type playerConfig = {
|
||||
speed: number;
|
||||
root: Element;
|
||||
loadTimeout: number;
|
||||
skipInactive: Boolean;
|
||||
};
|
||||
|
||||
type playerMetaData = {
|
||||
totalTime: number;
|
||||
};
|
||||
```
|
||||
|
||||
## REPL tool
|
||||
|
||||
You can also play with rrweb by using the REPL testing tool which does not need installation.
|
||||
|
||||
Run `npm run repl` to launch a browser and ask for a URL you want to test on the CLI:
|
||||
|
||||
```
|
||||
Enter the url you want to record, e.g https://react-redux.realworld.io:
|
||||
```
|
||||
|
||||
Waiting for the browser to open the specified page and print following messages on the CLI:
|
||||
|
||||
```
|
||||
Enter the url you want to record, e.g https://react-redux.realworld.io: https://github.com
|
||||
Going to open https://github.com...
|
||||
Ready to record. You can do any interaction on the page.
|
||||
Once you want to finish the recording, enter 'y' to start replay:
|
||||
```
|
||||
|
||||
At this point, you can interact in the web page. After the desired operations have been recorded, enter 'y' on the CLI, and the test tool will replay the operations to verify whether the recording was successful.
|
||||
|
||||
The following messages will be printed on the CLI during replay:
|
||||
|
||||
```
|
||||
Enter 'y' to persistently store these recorded events:
|
||||
```
|
||||
|
||||
At this point, you can enter 'y' again on the CLI. The test tool will save the recorded session into a static HTML file and prompt for the location:
|
||||
|
||||
```
|
||||
Saved at PATH_TO_YOUR_REPO/temp/replay_2018_11_23T07_53_30.html
|
||||
```
|
||||
|
||||
This file uses the latest rrweb bundle code, so we can run `npm run bundle:browser` after patching the code, then refresh the static file to see and debug the impact of the latest code on replay.
|
||||
@@ -81,6 +81,14 @@ function save() {
|
||||
setInterval(save, 10 * 1000);
|
||||
```
|
||||
|
||||
#### 隐私
|
||||
|
||||
页面中可能存在一些隐私相关的内容不希望被录制,rrweb 为此做了以下支持:
|
||||
|
||||
- 在 HTML 元素中添加类名 `.rr-block` 将会避免该元素及其子元素被录制,回放时取而代之的是一个同等宽高的占位元素。
|
||||
- 在 HTML 元素中添加类名 `.rr-ignore` 将会避免录制该元素的输入事件。
|
||||
- `input[type="password"]` 类型的密码输入框默认不会录制输入事件。
|
||||
|
||||
### 回放
|
||||
|
||||
回放时需要引入对应的 CSS 文件:
|
||||
@@ -101,6 +109,17 @@ const replayer = new rrweb.Replayer(events);
|
||||
replayer.play();
|
||||
```
|
||||
|
||||
#### 配置参数
|
||||
|
||||
可以通过 `new rrweb.Replayer(events, options)` 的方式向 rrweb 传递回放时的配置参数,具体配置如下:
|
||||
|
||||
| key | 默认值 | 功能 |
|
||||
| ----- | ------------- | -------- |
|
||||
| speed | 1 | 回放倍速 |
|
||||
| root | document.body | 回放时使用的 HTML 元素 |
|
||||
| loadTimeout | 0 | 加载异步样式表的超时时长 |
|
||||
| skipInactive | false | 是否快速跳过无用户操作的阶段 |
|
||||
|
||||
#### 使用 rrweb-player
|
||||
|
||||
rrweb 自带的回放只提供所有的 JS API 以及最基本的 UI,如果需要更强的回放播放器 UI,可以使用 rrweb-player。
|
||||
@@ -134,6 +153,50 @@ new rrwebPlayer({
|
||||
});
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### rrweb
|
||||
|
||||
#### rrweb.record
|
||||
|
||||
```typescript
|
||||
type record = (options: recordOptions) => listenerHandler;
|
||||
|
||||
type recordOptions = {
|
||||
emit: (e: eventWithTime) => void;
|
||||
};
|
||||
type listenerHandler = () => void;
|
||||
```
|
||||
|
||||
#### rrweb.Replayer
|
||||
|
||||
```typescript
|
||||
class Replayer {
|
||||
public wrapper: HTMLDivElement;
|
||||
|
||||
constructor(events: eventWithTime[], config?: Partial<playerConfig>);
|
||||
|
||||
public on(event: string, handler: mitt.Handler): void;
|
||||
public setConfig(config: Partial<playerConfig>): void;
|
||||
public getMetaData(): playerMetaData;
|
||||
public getTimeOffset(): number;
|
||||
public play(timeOffset?: number): void;
|
||||
public pause(): void;
|
||||
public resume(timeOffset?: number): void;
|
||||
}
|
||||
|
||||
type playerConfig = {
|
||||
speed: number;
|
||||
root: Element;
|
||||
loadTimeout: number;
|
||||
skipInactive: Boolean;
|
||||
};
|
||||
|
||||
type playerMetaData = {
|
||||
totalTime: number;
|
||||
};
|
||||
```
|
||||
|
||||
## REPL 工具
|
||||
|
||||
在不安装 rrweb 的情况下,也可以通过使用 REPL 工具试用 rrweb 录制 web 应用。
|
||||
|
||||
Reference in New Issue
Block a user